mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-147590 Mac ctrl-k shortcut in multiselect only operates on last cursor
This commit is contained in:
+6
-15
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -27,14 +27,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class CutLineActionHandler extends EditorWriteActionHandler {
|
||||
private final boolean myToLineStart;
|
||||
private final boolean myIgnoreSelection;
|
||||
private final boolean myCopyToClipboard;
|
||||
|
||||
CutLineActionHandler(boolean toLineStart, boolean ignoreSelection, boolean copyToClipboard) {
|
||||
super(!copyToClipboard); // as CutLineEndAction interacts with clipboard, multi-caret support for it needs to be implemented explicitly (todo)
|
||||
CutLineActionHandler(boolean toLineStart) {
|
||||
super(true);
|
||||
myToLineStart = toLineStart;
|
||||
myIgnoreSelection = ignoreSelection;
|
||||
myCopyToClipboard = copyToClipboard;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,7 +38,7 @@ class CutLineActionHandler extends EditorWriteActionHandler {
|
||||
if (caret == null) {
|
||||
caret = editor.getCaretModel().getCurrentCaret();
|
||||
}
|
||||
if (!myIgnoreSelection && caret.hasSelection()) {
|
||||
if (caret.hasSelection()) {
|
||||
delete(editor, caret, caret.getSelectionStart(), caret.getSelectionEnd());
|
||||
return;
|
||||
}
|
||||
@@ -79,13 +75,8 @@ class CutLineActionHandler extends EditorWriteActionHandler {
|
||||
delete(editor, caret, start, end);
|
||||
}
|
||||
|
||||
private void delete(@NotNull Editor editor, @NotNull Caret caret, int start, int end) {
|
||||
if (myCopyToClipboard) {
|
||||
KillRingUtil.copyToKillRing(editor, start, end, true);
|
||||
}
|
||||
else {
|
||||
CopyPasteManager.getInstance().stopKillRings();
|
||||
}
|
||||
private static void delete(@NotNull Editor editor, @NotNull Caret caret, int start, int end) {
|
||||
CopyPasteManager.getInstance().stopKillRings();
|
||||
editor.getDocument().deleteString(start, end);
|
||||
|
||||
// in case the caret was in the virtual space, we force it to go back to the real offset
|
||||
|
||||
+51
-1
@@ -24,8 +24,58 @@
|
||||
*/
|
||||
package com.intellij.openapi.editor.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler;
|
||||
import com.intellij.util.DocumentUtil;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CutLineEndAction extends TextComponentEditorAction {
|
||||
public CutLineEndAction() {
|
||||
super(new CutLineActionHandler(false, true, true));
|
||||
super(new Handler());
|
||||
}
|
||||
|
||||
private static class Handler extends EditorWriteActionHandler {
|
||||
private Handler() {
|
||||
super(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeWriteAction(final Editor editor, @Nullable Caret caret, DataContext dataContext) {
|
||||
if (caret == null && editor.getCaretModel().getCaretCount() > 1) {
|
||||
editor.getCaretModel().runForEachCaret(new CaretAction() {
|
||||
@Override
|
||||
public void perform(Caret caret) {
|
||||
caret.setSelection(caret.getOffset(), getEndOffset(caret));
|
||||
}
|
||||
});
|
||||
// We don't support kill-ring operations for multiple carets currently
|
||||
EditorCopyPasteHelper.getInstance().copySelectionToClipboard(editor);
|
||||
EditorModificationUtil.deleteSelectedTextForAllCarets(editor);
|
||||
}
|
||||
else {
|
||||
if (caret == null) {
|
||||
caret = editor.getCaretModel().getCurrentCaret();
|
||||
}
|
||||
int startOffset = caret.getOffset();
|
||||
int endOffset = getEndOffset(caret);
|
||||
KillRingUtil.cut(editor, startOffset, endOffset);
|
||||
// in case the caret was in the virtual space, we force it to go back to the real offset
|
||||
caret.moveToOffset(startOffset);
|
||||
}
|
||||
}
|
||||
|
||||
private static int getEndOffset(@NotNull Caret caret) {
|
||||
Document document = caret.getEditor().getDocument();
|
||||
int startOffset = caret.getOffset();
|
||||
int endOffset = DocumentUtil.getLineEndOffset(startOffset, document);
|
||||
if (endOffset < document.getTextLength() &&
|
||||
CharArrayUtil.isEmptyOrSpaces(document.getImmutableCharSequence(), startOffset, endOffset)) {
|
||||
endOffset++;
|
||||
}
|
||||
return endOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -19,6 +19,6 @@ import com.intellij.openapi.editor.actionSystem.EditorAction;
|
||||
|
||||
public class DeleteToLineEndAction extends EditorAction {
|
||||
public DeleteToLineEndAction() {
|
||||
super(new CutLineActionHandler(false, false, false));
|
||||
super(new CutLineActionHandler(false));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -19,6 +19,6 @@ import com.intellij.openapi.editor.actionSystem.EditorAction;
|
||||
|
||||
public class DeleteToLineStartAction extends EditorAction {
|
||||
public DeleteToLineStartAction() {
|
||||
super(new CutLineActionHandler(true, false, false));
|
||||
super(new CutLineActionHandler(true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
li<caret>
|
||||
line<caret>
|
||||
@@ -0,0 +1,2 @@
|
||||
li<caret>ne1
|
||||
li<selection>ne<caret></selection>2
|
||||
Reference in New Issue
Block a user