From cebf53b5d13eab538df02f9c3c223e3e91082dd7 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 11 Mar 2016 16:19:53 +0100 Subject: [PATCH] don't take write actions for modifying TextComponentEditor --- .../EditorWriteActionHandler.java | 10 +++++-- .../editor/textarea/TextComponentEditor.java | 28 +++++++++++++++++++ .../editor/actions/KillRingSaveAction.java | 12 ++++++-- .../actions/TextComponentEditorAction.java | 4 +-- ...itor.java => TextComponentEditorImpl.java} | 4 +-- 5 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 platform/platform-api/src/com/intellij/openapi/editor/textarea/TextComponentEditor.java rename platform/platform-impl/src/com/intellij/openapi/editor/textarea/{TextComponentEditor.java => TextComponentEditorImpl.java} (97%) diff --git a/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/EditorWriteActionHandler.java b/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/EditorWriteActionHandler.java index 879f921afe67..163f7cff058b 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/EditorWriteActionHandler.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/EditorWriteActionHandler.java @@ -19,6 +19,7 @@ import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.*; +import com.intellij.openapi.editor.textarea.TextComponentEditor; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.project.Project; import org.jetbrains.annotations.Nullable; @@ -46,7 +47,7 @@ public abstract class EditorWriteActionHandler extends EditorActionHandler { if (project != null && !FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) return; } - ApplicationManager.getApplication().runWriteAction(new DocumentRunnable(editor.getDocument(),editor.getProject()) { + DocumentRunnable runnable = new DocumentRunnable(editor.getDocument(), editor.getProject()) { @Override public void run() { final Document doc = editor.getDocument(); @@ -62,7 +63,12 @@ public abstract class EditorWriteActionHandler extends EditorActionHandler { doc.stopGuardedBlockChecking(); } } - }); + }; + if (editor instanceof TextComponentEditor) { + runnable.run(); + } else { + ApplicationManager.getApplication().runWriteAction(runnable); + } } /** diff --git a/platform/platform-api/src/com/intellij/openapi/editor/textarea/TextComponentEditor.java b/platform/platform-api/src/com/intellij/openapi/editor/textarea/TextComponentEditor.java new file mode 100644 index 000000000000..0c40a508ef5c --- /dev/null +++ b/platform/platform-api/src/com/intellij/openapi/editor/textarea/TextComponentEditor.java @@ -0,0 +1,28 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.editor.textarea; + +import com.intellij.openapi.editor.Editor; + +import javax.swing.text.Document; + +/** + * An implementation of {@link Editor} on top of a plain {@link javax.swing.text.JTextComponent}. + * The corresponding document ({@link #getDocument()}) is a wrapper over Swing {@link Document} and + * doesn't require write action for modifications. + */ +public interface TextComponentEditor extends Editor { +} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/KillRingSaveAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/KillRingSaveAction.java index 79453662de17..f9a1b5ff4d39 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/KillRingSaveAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/KillRingSaveAction.java @@ -21,6 +21,7 @@ import com.intellij.openapi.editor.DocumentRunnable; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.SelectionModel; import com.intellij.openapi.editor.actionSystem.EditorActionHandler; +import com.intellij.openapi.editor.textarea.TextComponentEditor; import com.intellij.openapi.ide.KillRingTransferable; /** @@ -61,13 +62,18 @@ public class KillRingSaveAction extends TextComponentEditorAction { } KillRingUtil.copyToKillRing(editor, start, end, false); if (myRemove) { - ApplicationManager.getApplication().runWriteAction(new DocumentRunnable(editor.getDocument(),editor.getProject()) { + DocumentRunnable runnable = new DocumentRunnable(editor.getDocument(), editor.getProject()) { @Override public void run() { editor.getDocument().deleteString(start, end); } - }); - } + }; + if (editor instanceof TextComponentEditor) { + runnable.run(); + } else { + ApplicationManager.getApplication().runWriteAction(runnable); + } + } } } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/TextComponentEditorAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/TextComponentEditorAction.java index 4f76b927f5d4..5db1c6513e7f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/TextComponentEditorAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/TextComponentEditorAction.java @@ -21,7 +21,7 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.actionSystem.EditorAction; import com.intellij.openapi.editor.actionSystem.EditorActionHandler; -import com.intellij.openapi.editor.textarea.TextComponentEditor; +import com.intellij.openapi.editor.textarea.TextComponentEditorImpl; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -47,7 +47,7 @@ public abstract class TextComponentEditorAction extends EditorAction { if (editor != null) return editor; final Object data = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext); if (data instanceof JTextComponent) { - return new TextComponentEditor(CommonDataKeys.PROJECT.getData(dataContext), (JTextComponent) data); + return new TextComponentEditorImpl(CommonDataKeys.PROJECT.getData(dataContext), (JTextComponent) data); } return null; } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentEditor.java b/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentEditorImpl.java similarity index 97% rename from platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentEditor.java rename to platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentEditorImpl.java index 6266a81b539f..8fdeec5aefd8 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentEditor.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentEditorImpl.java @@ -37,7 +37,7 @@ import java.awt.event.MouseEvent; /** * @author yole */ -public class TextComponentEditor extends UserDataHolderBase implements Editor { +public class TextComponentEditorImpl extends UserDataHolderBase implements TextComponentEditor { private final Project myProject; private final JTextComponent myTextComponent; private final TextComponentDocument myDocument; @@ -48,7 +48,7 @@ public class TextComponentEditor extends UserDataHolderBase implements Editor { private final TextComponentFoldingModel myFoldingModel; private EditorSettings mySettings; - public TextComponentEditor(final Project project, @NotNull JTextComponent textComponent) { + public TextComponentEditorImpl(final Project project, @NotNull JTextComponent textComponent) { myProject = project; myTextComponent = textComponent; if (textComponent instanceof JTextArea) {