use of com.maddyhome.idea.vim.common.TextRange in project ideavim by JetBrains.
the class JoinLinesHandler method execute.
public boolean execute(@NotNull Editor editor, @NotNull DataContext context, @NotNull ExCommand cmd) throws ExException {
StringBuilder arg = new StringBuilder(cmd.getArgument());
boolean spaces = true;
if (arg.length() > 0 && arg.charAt(0) == '!') {
spaces = false;
arg.deleteCharAt(0);
}
TextRange range = cmd.getTextRange(editor, context, true);
range = new TextRange(range.getStartOffset(), range.getEndOffset() - 1);
return VimPlugin.getChange().deleteJoinRange(editor, range, spaces);
}
use of com.maddyhome.idea.vim.common.TextRange in project ideavim by JetBrains.
the class MoveTextHandler method execute.
public boolean execute(@NotNull Editor editor, @NotNull DataContext context, @NotNull ExCommand cmd) throws ExException {
TextRange range = cmd.getTextRange(editor, context, false);
LineRange lr = cmd.getLineRange(editor, context);
int adj = lr.getEndLine() - lr.getStartLine() + 1;
final ExCommand argumentCmd = CommandParser.getInstance().parse(cmd.getArgument());
int line = argumentCmd.getRanges().getFirstLine(editor, context);
if (line >= lr.getEndLine()) {
line -= adj;
} else if (line >= lr.getStartLine()) {
throw new InvalidRangeException(MessageHelper.message(Msg.e_backrange));
}
String text = EditorHelper.getText(editor, range.getStartOffset(), range.getEndOffset());
editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
int offset = VimPlugin.getMotion().moveCaretToLineStart(editor, line + 1);
VimPlugin.getCopy().putText(editor, context, offset, text, SelectionType.LINE_WISE, 1, true, false, CommandState.SubMode.NONE);
return true;
}
use of com.maddyhome.idea.vim.common.TextRange in project ideavim by JetBrains.
the class ShiftLeftHandler method execute.
public boolean execute(@NotNull Editor editor, @NotNull DataContext context, @NotNull ExCommand cmd) {
TextRange range = cmd.getTextRange(editor, context, true);
VimPlugin.getChange().indentRange(editor, context, range, cmd.getCommand().length(), -1);
return true;
}
use of com.maddyhome.idea.vim.common.TextRange in project ideavim by JetBrains.
the class MarkGroup method getMarksRange.
@Nullable
private TextRange getMarksRange(@NotNull Editor editor, char startMark, char endMark) {
final Mark start = getMark(editor, startMark);
final Mark end = getMark(editor, endMark);
if (start != null && end != null) {
final int startOffset = EditorHelper.getOffset(editor, start.getLogicalLine(), start.getCol());
final int endOffset = EditorHelper.getOffset(editor, end.getLogicalLine(), end.getCol());
return new TextRange(startOffset, endOffset);
}
return null;
}
use of com.maddyhome.idea.vim.common.TextRange in project ideavim by JetBrains.
the class ChangeGroup method insertDeletePreviousWord.
/**
* Deletes the text from the cursor to the start of the previous word
*
* @param editor The editor to delete the text from
* @return true if able to delete text, false if not
*/
public boolean insertDeletePreviousWord(@NotNull Editor editor) {
final int deleteTo = VimPlugin.getMotion().moveCaretToNextWord(editor, -1, false);
if (deleteTo == -1) {
return false;
}
final TextRange range = new TextRange(deleteTo, editor.getCaretModel().getOffset());
deleteRange(editor, range, SelectionType.CHARACTER_WISE, true);
return true;
}
Aggregations