don't take write actions for modifying TextComponentEditor

This commit is contained in:
peter
2016-03-11 16:23:14 +01:00
parent 5bc0d94602
commit cebf53b5d1
5 changed files with 49 additions and 9 deletions
@@ -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);
}
}
/**
@@ -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 {
}
@@ -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);
}
}
}
}
}
@@ -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;
}
@@ -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) {