mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-03-06 00:32:52 +01:00
Fix goto mark actions
This commit is contained in:
parent
a7e1275b5f
commit
392f8e5e60
src/com/maddyhome/idea/vim
@ -19,7 +19,6 @@
|
||||
package com.maddyhome.idea.vim.action.motion.mark;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.action.motion.MotionEditorAction;
|
||||
@ -32,23 +31,16 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public class MotionGotoFileMarkAction extends MotionEditorAction {
|
||||
public MotionGotoFileMarkAction() {
|
||||
super(new Handler());
|
||||
}
|
||||
super(new MotionEditorActionHandler() {
|
||||
@Override
|
||||
public int getOffset(@NotNull Editor editor, @NotNull DataContext context, int count, int rawCount,
|
||||
@Nullable Argument argument) {
|
||||
if (argument == null) return -1;
|
||||
|
||||
private static class Handler extends MotionEditorActionHandler {
|
||||
Handler() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOffset(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context, int count,
|
||||
int rawCount, @Nullable Argument argument) {
|
||||
if (argument == null) {
|
||||
return -1;
|
||||
final char mark = argument.getCharacter();
|
||||
return VimPlugin.getMotion().moveCaretToFileMark(editor, mark, false);
|
||||
}
|
||||
|
||||
final char mark = argument.getCharacter();
|
||||
return VimPlugin.getMotion().moveCaretToMark(editor, caret, mark, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
package com.maddyhome.idea.vim.action.motion.mark;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.action.motion.MotionEditorAction;
|
||||
@ -32,23 +31,15 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public class MotionGotoFileMarkLineAction extends MotionEditorAction {
|
||||
public MotionGotoFileMarkLineAction() {
|
||||
super(new Handler());
|
||||
}
|
||||
super(new MotionEditorActionHandler() {
|
||||
@Override
|
||||
public int getOffset(@NotNull Editor editor, @NotNull DataContext context, int count, int rawCount,
|
||||
@Nullable Argument argument) {
|
||||
if (argument == null) return -1;
|
||||
|
||||
private static class Handler extends MotionEditorActionHandler {
|
||||
Handler() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOffset(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context, int count,
|
||||
int rawCount, @Nullable Argument argument) {
|
||||
if (argument == null) {
|
||||
return -1;
|
||||
final char mark = argument.getCharacter();
|
||||
return VimPlugin.getMotion().moveCaretToFileMark(editor, mark, true);
|
||||
}
|
||||
|
||||
final char mark = argument.getCharacter();
|
||||
return VimPlugin.getMotion().moveCaretToMark(editor, caret, mark, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
package com.maddyhome.idea.vim.action.motion.mark;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.action.motion.MotionEditorAction;
|
||||
@ -32,23 +31,15 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public class MotionGotoMarkAction extends MotionEditorAction {
|
||||
public MotionGotoMarkAction() {
|
||||
super(new Handler());
|
||||
}
|
||||
super(new MotionEditorActionHandler() {
|
||||
@Override
|
||||
public int getOffset(@NotNull Editor editor, @NotNull DataContext context, int count, int rawCount,
|
||||
@Nullable Argument argument) {
|
||||
if (argument == null) return -1;
|
||||
|
||||
private static class Handler extends MotionEditorActionHandler {
|
||||
Handler() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOffset(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context, int count,
|
||||
int rawCount, @Nullable Argument argument) {
|
||||
if (argument == null) {
|
||||
return -1;
|
||||
final char mark = argument.getCharacter();
|
||||
return VimPlugin.getMotion().moveCaretToMark(editor, mark, false);
|
||||
}
|
||||
|
||||
final char mark = argument.getCharacter();
|
||||
return VimPlugin.getMotion().moveCaretToMark(editor, caret, mark, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
package com.maddyhome.idea.vim.action.motion.mark;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.action.motion.MotionEditorAction;
|
||||
@ -32,24 +31,15 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public class MotionGotoMarkLineAction extends MotionEditorAction {
|
||||
public MotionGotoMarkLineAction() {
|
||||
super(new Handler());
|
||||
}
|
||||
super(new MotionEditorActionHandler() {
|
||||
@Override
|
||||
public int getOffset(@NotNull Editor editor, @NotNull DataContext context, int count, int rawCount,
|
||||
@Nullable Argument argument) {
|
||||
if (argument == null) return -1;
|
||||
|
||||
|
||||
private static class Handler extends MotionEditorActionHandler {
|
||||
Handler() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOffset(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context, int count,
|
||||
int rawCount, @Nullable Argument argument) {
|
||||
if (argument == null) {
|
||||
return -1;
|
||||
final char mark = argument.getCharacter();
|
||||
return VimPlugin.getMotion().moveCaretToMark(editor, mark, true);
|
||||
}
|
||||
|
||||
final char mark = argument.getCharacter();
|
||||
return VimPlugin.getMotion().moveCaretToMark(editor, caret, mark, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -405,69 +405,35 @@ public class MotionGroup {
|
||||
return Math.max(0, Math.min(count, EditorHelper.getFileSize(editor) - 1));
|
||||
}
|
||||
|
||||
public int moveCaretToMark(@NotNull Editor editor, @NotNull Caret caret, char ch) {
|
||||
final Mark mark = VimPlugin.getMark().getMark(editor, ch);
|
||||
if (mark == null) {
|
||||
return -1;
|
||||
}
|
||||
public int moveCaretToFileMark(@NotNull Editor editor, char ch, boolean toLineStart) {
|
||||
final Mark mark = VimPlugin.getMark().getFileMark(editor, ch);
|
||||
if (mark == null) return -1;
|
||||
|
||||
final VirtualFile vf = EditorData.getVirtualFile(editor);
|
||||
if (vf == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
final LogicalPosition lp = new LogicalPosition(mark.getLogicalLine(), mark.getCol());
|
||||
if (!vf.getPath().equals(mark.getFilename())) {
|
||||
final Editor selectedEditor = selectEditor(editor, mark);
|
||||
if (selectedEditor != null) {
|
||||
editor.getCaretModel().removeCaret(caret);
|
||||
final Caret newCaret = selectedEditor.getCaretModel().addCaret(selectedEditor.logicalToVisualPosition(lp),
|
||||
false);
|
||||
if (newCaret != null) {
|
||||
moveCaret(selectedEditor, newCaret, selectedEditor.logicalPositionToOffset(lp));
|
||||
}
|
||||
}
|
||||
|
||||
return -2;
|
||||
}
|
||||
else {
|
||||
return editor.logicalPositionToOffset(lp);
|
||||
}
|
||||
final int line = mark.getLogicalLine();
|
||||
return toLineStart ? moveCaretToLineStartSkipLeading(editor, line)
|
||||
: editor.logicalPositionToOffset(new LogicalPosition(line, mark.getCol()));
|
||||
}
|
||||
|
||||
public int moveCaretToMark(@NotNull Editor editor, @NotNull Caret caret, char ch, boolean toLineStart) {
|
||||
public int moveCaretToMark(@NotNull Editor editor, char ch, boolean toLineStart) {
|
||||
final Mark mark = VimPlugin.getMark().getMark(editor, ch);
|
||||
if (mark == null) {
|
||||
return -1;
|
||||
}
|
||||
if (mark == null) return -1;
|
||||
|
||||
final VirtualFile vf = EditorData.getVirtualFile(editor);
|
||||
if (vf == null) {
|
||||
return -1;
|
||||
if (vf == null) return -1;
|
||||
|
||||
final int line = mark.getLogicalLine();
|
||||
if (vf.getPath().equals(mark.getFilename())) {
|
||||
return toLineStart ? moveCaretToLineStartSkipLeading(editor, line)
|
||||
: editor.logicalPositionToOffset(new LogicalPosition(line, mark.getCol()));
|
||||
}
|
||||
|
||||
final LogicalPosition lp = new LogicalPosition(mark.getLogicalLine(), mark.getCol());
|
||||
if (!vf.getPath().equals(mark.getFilename())) {
|
||||
final Editor selectedEditor = selectEditor(editor, mark);
|
||||
if (selectedEditor != null) {
|
||||
editor.getCaretModel().removeCaret(caret);
|
||||
final Caret newCaret = selectedEditor.getCaretModel().addCaret(selectedEditor.logicalToVisualPosition(lp),
|
||||
false);
|
||||
if (newCaret != null) {
|
||||
final int offset = toLineStart
|
||||
? moveCaretToLineStartSkipLeading(selectedEditor, lp.line)
|
||||
: selectedEditor.logicalPositionToOffset(lp);
|
||||
moveCaret(selectedEditor, newCaret, offset);
|
||||
}
|
||||
}
|
||||
|
||||
return -2;
|
||||
}
|
||||
else {
|
||||
return toLineStart
|
||||
? moveCaretToLineStartSkipLeading(editor, lp.line)
|
||||
: editor.logicalPositionToOffset(lp);
|
||||
final Editor selectedEditor = selectEditor(editor, mark);
|
||||
if (selectedEditor != null) {
|
||||
moveCaret(selectedEditor, selectedEditor.getCaretModel().getPrimaryCaret(),
|
||||
toLineStart ? moveCaretToLineStartSkipLeading(selectedEditor, line)
|
||||
: selectedEditor.logicalPositionToOffset(new LogicalPosition(line, mark.getCol())));
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
public int moveCaretToJump(@NotNull Editor editor, @NotNull Caret caret, int count) {
|
||||
@ -1218,21 +1184,6 @@ public class MotionGroup {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated To move the caret, use {@link #moveCaret(Editor, Caret, int)}
|
||||
*/
|
||||
public int moveCaretHorizontal(@NotNull Editor editor, int count, boolean allowPastEnd) {
|
||||
int oldOffset = editor.getCaretModel().getOffset();
|
||||
int offset = EditorHelper
|
||||
.normalizeOffset(editor, editor.getCaretModel().getLogicalPosition().line, oldOffset + count, allowPastEnd);
|
||||
if (offset == oldOffset) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return offset;
|
||||
}
|
||||
}
|
||||
|
||||
public int moveCaretHorizontal(@NotNull Editor editor, @NotNull Caret caret, int count, boolean allowPastEnd) {
|
||||
int oldOffset = caret.getOffset();
|
||||
int offset = EditorHelper.normalizeOffset(editor, caret.getLogicalPosition().line, oldOffset + count, allowPastEnd);
|
||||
|
Loading…
Reference in New Issue
Block a user