mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-72454 hungs up after attempt to select text [more cases]
This commit is contained in:
@@ -69,10 +69,22 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser
|
||||
return;
|
||||
}
|
||||
|
||||
DataContext context = new DataContext() {
|
||||
@Override
|
||||
public Object getData(@NonNls String dataId) {
|
||||
if (TRANSFERABLE_PROVIDER.equals(dataId)) {
|
||||
return transferableProvider;
|
||||
}
|
||||
|
||||
return dataContext.getData(dataId);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
final Project project = editor.getProject();
|
||||
if (project == null || editor.isColumnMode() || editor.getSelectionModel().hasBlockSelection()) {
|
||||
if (myOriginalHandler != null) {
|
||||
myOriginalHandler.execute(editor, dataContext);
|
||||
myOriginalHandler.execute(editor, context);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -81,24 +93,13 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser
|
||||
|
||||
if (file == null) {
|
||||
if (myOriginalHandler != null) {
|
||||
myOriginalHandler.execute(editor, dataContext);
|
||||
myOriginalHandler.execute(editor, context);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
document.startGuardedBlockChecking();
|
||||
try {
|
||||
DataContext context = new DataContext() {
|
||||
@Override
|
||||
public Object getData(@NonNls String dataId) {
|
||||
if (TRANSFERABLE_PROVIDER.equals(dataId)) {
|
||||
return transferableProvider;
|
||||
}
|
||||
|
||||
return dataContext.getData(dataId);
|
||||
}
|
||||
};
|
||||
|
||||
for(PasteProvider provider: Extensions.getExtensions(EP_NAME)) {
|
||||
if (provider.isPasteEnabled(context)) {
|
||||
provider.performPaste(context);
|
||||
|
||||
@@ -169,8 +169,14 @@ public class EditorModificationUtil {
|
||||
}
|
||||
|
||||
public static void pasteFromClipboardAsBlock(Editor editor) {
|
||||
Transferable content = getClipboardContent(editor);
|
||||
pasteTransferableAsBlock(editor, null);
|
||||
}
|
||||
|
||||
public static void pasteTransferableAsBlock(Editor editor, @Nullable Transferable content) {
|
||||
if (content == null) {
|
||||
content = getClipboardContent(editor);
|
||||
}
|
||||
|
||||
if (content != null) {
|
||||
try {
|
||||
int caretLine = editor.getCaretModel().getLogicalPosition().line;
|
||||
|
||||
@@ -30,18 +30,28 @@ import com.intellij.openapi.editor.EditorModificationUtil;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorAction;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.util.Producer;
|
||||
|
||||
import java.awt.datatransfer.Transferable;
|
||||
|
||||
public class PasteAction extends EditorAction {
|
||||
public static final String TRANSFERABLE_PROVIDER = "PasteTransferableProvider";
|
||||
|
||||
public PasteAction() {
|
||||
super(new Handler());
|
||||
}
|
||||
|
||||
private static class Handler extends EditorWriteActionHandler {
|
||||
public void executeWriteAction(Editor editor, DataContext dataContext) {
|
||||
Producer<Transferable> producer = (Producer<Transferable>)dataContext.getData(TRANSFERABLE_PROVIDER);
|
||||
|
||||
if (editor.isColumnMode() || editor.getSelectionModel().hasBlockSelection()) {
|
||||
EditorModificationUtil.pasteFromClipboardAsBlock(editor);
|
||||
} else {
|
||||
editor.putUserData(EditorEx.LAST_PASTED_REGION, EditorModificationUtil.pasteFromClipboard(editor));
|
||||
EditorModificationUtil.pasteTransferableAsBlock(editor, producer == null ? null : producer.produce());
|
||||
}
|
||||
else {
|
||||
editor.putUserData(EditorEx.LAST_PASTED_REGION,
|
||||
producer == null ? EditorModificationUtil.pasteFromClipboard(editor) :
|
||||
EditorModificationUtil.pasteFromTransferrable(producer.produce(), editor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-2
@@ -32,6 +32,9 @@ import com.intellij.openapi.editor.EditorModificationUtil;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorAction;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.util.Producer;
|
||||
|
||||
import java.awt.datatransfer.Transferable;
|
||||
|
||||
public class SimplePasteAction extends EditorAction {
|
||||
public SimplePasteAction() {
|
||||
@@ -48,10 +51,16 @@ public class SimplePasteAction extends EditorAction {
|
||||
|
||||
private static class Handler extends EditorWriteActionHandler {
|
||||
public void executeWriteAction(Editor editor, DataContext dataContext) {
|
||||
Producer<Transferable> producer = (Producer<Transferable>) dataContext.getData(PasteAction.TRANSFERABLE_PROVIDER);
|
||||
|
||||
if (editor.isColumnMode()) {
|
||||
EditorModificationUtil.pasteFromClipboardAsBlock(editor);
|
||||
EditorModificationUtil.pasteTransferableAsBlock(editor, producer == null ? null : producer.produce());
|
||||
} else {
|
||||
editor.putUserData(EditorEx.LAST_PASTED_REGION, EditorModificationUtil.pasteFromClipboard(editor));
|
||||
editor.putUserData(EditorEx.LAST_PASTED_REGION,
|
||||
producer == null ?
|
||||
EditorModificationUtil.pasteFromClipboard(editor)
|
||||
: EditorModificationUtil.pasteFromTransferrable(producer.produce(), editor));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user