mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-10 06:40:37 +02:00
Better work with nullable carets
This commit is contained in:
parent
d5313ebbda
commit
ac10b96280
src/com/maddyhome/idea/vim/handler
@ -35,7 +35,7 @@ import java.util.List;
|
||||
/**
|
||||
*/
|
||||
public abstract class ChangeEditorActionHandler extends EditorActionHandlerBase {
|
||||
private boolean myIsMulticaretChangeAction = false;
|
||||
private boolean myIsMulticaretChangeAction;
|
||||
private CaretOrder myCaretOrder;
|
||||
|
||||
public ChangeEditorActionHandler(boolean runForEachCaret, CaretOrder caretOrder) {
|
||||
|
@ -58,7 +58,7 @@ public abstract class EditorActionHandlerBase extends EditorActionHandler {
|
||||
|
||||
try {
|
||||
if (myRunForEachCaret) {
|
||||
if (cmd == null || !execute(editor, caret, context, cmd)) {
|
||||
if (cmd == null || caret == null || !execute(editor, caret, context, cmd)) {
|
||||
VimPlugin.indicateError();
|
||||
}
|
||||
}
|
||||
@ -85,11 +85,8 @@ public abstract class EditorActionHandlerBase extends EditorActionHandler {
|
||||
return execute(editor, editor.getCaretModel().getPrimaryCaret(), context, cmd);
|
||||
}
|
||||
|
||||
protected boolean execute(@NotNull Editor editor, @Nullable Caret caret, @NotNull DataContext context,
|
||||
protected boolean execute(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context,
|
||||
@NotNull Command cmd) throws ExecuteMethodNotOverriddenException {
|
||||
if (caret == null) {
|
||||
return false;
|
||||
}
|
||||
if (myRunForEachCaret) {
|
||||
throw new ExecuteMethodNotOverriddenException(this.getClass());
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ public abstract class MotionEditorActionHandler extends EditorActionHandlerBase
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final boolean execute(@NotNull Editor editor, @Nullable Caret caret, @NotNull DataContext context,
|
||||
protected final boolean execute(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context,
|
||||
@NotNull Command cmd) {
|
||||
if (!CommandState.inVisualBlockMode(editor)) {
|
||||
// It comes out that merging of the overlapping selections is done by IDE. In ideavim we should be
|
||||
@ -92,9 +92,6 @@ public abstract class MotionEditorActionHandler extends EditorActionHandlerBase
|
||||
// set up the caret data to the actual values.
|
||||
@NotNull Caret currentCaret;
|
||||
if (myRunForEachCaret) {
|
||||
if (caret == null) {
|
||||
return false;
|
||||
}
|
||||
currentCaret = caret;
|
||||
}
|
||||
else {
|
||||
@ -104,9 +101,6 @@ public abstract class MotionEditorActionHandler extends EditorActionHandlerBase
|
||||
}
|
||||
|
||||
if (myRunForEachCaret) {
|
||||
if (caret == null) {
|
||||
return false;
|
||||
}
|
||||
if (CommandState.inVisualBlockMode(editor) && caret != editor.getCaretModel().getPrimaryCaret()) {
|
||||
// In visual block mode, ideavim creates multiple carets to make a selection on each line.
|
||||
// Only the primary caret of the selection should be moved though. This temporary hack
|
||||
@ -121,9 +115,6 @@ public abstract class MotionEditorActionHandler extends EditorActionHandlerBase
|
||||
|
||||
int offset;
|
||||
if (myRunForEachCaret) {
|
||||
if (caret == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
offset = getOffset(editor, caret, context, cmd.getCount(), cmd.getRawCount(), cmd.getArgument());
|
||||
}
|
||||
@ -152,9 +143,6 @@ public abstract class MotionEditorActionHandler extends EditorActionHandlerBase
|
||||
offset = EditorHelper.normalizeOffset(editor, offset, false);
|
||||
}
|
||||
if (myRunForEachCaret) {
|
||||
if (caret == null) {
|
||||
return false;
|
||||
}
|
||||
MotionGroup.moveCaret(editor, caret, offset);
|
||||
postMove(editor, caret, context, cmd);
|
||||
}
|
||||
|
@ -42,13 +42,10 @@ public abstract class TextObjectActionHandler extends EditorActionHandlerBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final boolean execute(@NotNull Editor editor, @Nullable Caret caret, @NotNull DataContext context,
|
||||
protected final boolean execute(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context,
|
||||
@NotNull Command cmd) {
|
||||
if (CommandState.getInstance(editor).getMode() == CommandState.Mode.VISUAL) {
|
||||
TextRange range;
|
||||
if (caret == null) {
|
||||
return false;
|
||||
}
|
||||
range = getRange(editor, caret, context, cmd.getCount(), cmd.getRawCount(), cmd.getArgument());
|
||||
|
||||
if (range == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user