use of com.maddyhome.idea.vim.option.BoundStringOption in project ideavim by JetBrains.
the class MotionGroup method updateSelection.
private void updateSelection(@NotNull Editor editor, int offset) {
visualEnd = offset;
visualOffset = offset;
int start = visualStart;
int end = visualEnd;
final CommandState.SubMode subMode = CommandState.getInstance(editor).getSubMode();
if (subMode == CommandState.SubMode.VISUAL_CHARACTER) {
if (start > end) {
int t = start;
start = end;
end = t;
}
final BoundStringOption opt = (BoundStringOption) Options.getInstance().getOption("selection");
int lineEnd = EditorHelper.getLineEndForOffset(editor, end);
final int adj = opt.getValue().equals("exclusive") || end == lineEnd ? 0 : 1;
end = Math.min(EditorHelper.getFileSize(editor), end + adj);
editor.getSelectionModel().setSelection(start, end);
} else if (subMode == CommandState.SubMode.VISUAL_LINE) {
if (start > end) {
int t = start;
start = end;
end = t;
}
start = EditorHelper.getLineStartForOffset(editor, start);
end = EditorHelper.getLineEndForOffset(editor, end);
editor.getSelectionModel().setSelection(start, end);
} else if (subMode == CommandState.SubMode.VISUAL_BLOCK) {
LogicalPosition blockStart = editor.offsetToLogicalPosition(start);
LogicalPosition blockEnd = editor.offsetToLogicalPosition(end);
if (blockStart.column < blockEnd.column) {
blockEnd = new LogicalPosition(blockEnd.line, blockEnd.column + 1);
} else {
blockStart = new LogicalPosition(blockStart.line, blockStart.column + 1);
}
editor.getSelectionModel().setBlockSelection(blockStart, blockEnd);
for (Caret caret : editor.getCaretModel().getAllCarets()) {
int line = caret.getLogicalPosition().line;
int lineEndOffset = EditorHelper.getLineEndOffset(editor, line, true);
if (EditorData.getLastColumn(editor) >= MotionGroup.LAST_COLUMN) {
caret.setSelection(caret.getSelectionStart(), lineEndOffset);
}
if (!EditorHelper.isLineEmpty(editor, line, false)) {
caret.moveToOffset(caret.getSelectionEnd() - 1);
}
}
editor.getCaretModel().moveToOffset(end);
}
VimPlugin.getMark().setVisualSelectionMarks(editor, new TextRange(start, end));
}
use of com.maddyhome.idea.vim.option.BoundStringOption in project ideavim by JetBrains.
the class MotionGroup method setVisualMode.
public void setVisualMode(@NotNull Editor editor, @NotNull CommandState.SubMode mode) {
CommandState.SubMode oldMode = CommandState.getInstance(editor).getSubMode();
if (mode == CommandState.SubMode.NONE) {
int start = editor.getSelectionModel().getSelectionStart();
int end = editor.getSelectionModel().getSelectionEnd();
if (start != end) {
int line = editor.offsetToLogicalPosition(start).line;
int logicalStart = EditorHelper.getLineStartOffset(editor, line);
int lend = EditorHelper.getLineEndOffset(editor, line, true);
if (logicalStart == start && lend + 1 == end) {
mode = CommandState.SubMode.VISUAL_LINE;
} else {
mode = CommandState.SubMode.VISUAL_CHARACTER;
}
}
}
if (oldMode == CommandState.SubMode.NONE && mode == CommandState.SubMode.NONE) {
editor.getSelectionModel().removeSelection();
return;
}
if (mode == CommandState.SubMode.NONE) {
exitVisual(editor);
} else {
CommandState.getInstance(editor).pushState(CommandState.Mode.VISUAL, mode, MappingMode.VISUAL);
}
KeyHandler.getInstance().reset(editor);
visualStart = editor.getSelectionModel().getSelectionStart();
visualEnd = editor.getSelectionModel().getSelectionEnd();
if (CommandState.getInstance(editor).getSubMode() == CommandState.SubMode.VISUAL_CHARACTER) {
BoundStringOption opt = (BoundStringOption) Options.getInstance().getOption("selection");
int adj = 1;
if (opt.getValue().equals("exclusive")) {
adj = 0;
}
visualEnd -= adj;
}
visualOffset = editor.getCaretModel().getOffset();
VimPlugin.getMark().setVisualSelectionMarks(editor, getRawVisualRange());
}
Aggregations