use of com.maddyhome.idea.vim.common.TextRange in project ideavim by JetBrains.
the class ChangeGroup method autoIndentLines.
public void autoIndentLines(@NotNull Editor editor, @NotNull DataContext context, int lines) {
CaretModel caretModel = editor.getCaretModel();
int startLine = caretModel.getLogicalPosition().line;
int endLine = startLine + lines - 1;
if (endLine <= EditorHelper.getLineCount(editor)) {
TextRange textRange = new TextRange(caretModel.getOffset(), editor.getDocument().getLineEndOffset(endLine));
autoIndentRange(editor, context, textRange);
}
}
use of com.maddyhome.idea.vim.common.TextRange in project ideavim by JetBrains.
the class ChangeGroup method replaceText.
/**
* Replace text in the editor
*
* @param editor The editor to replace text in
* @param start The start offset to change
* @param end The end offset to change
* @param str The new text
*/
private void replaceText(@NotNull Editor editor, int start, int end, @NotNull String str) {
editor.getDocument().replaceString(start, end, str);
final int newEnd = start + str.length();
VimPlugin.getMark().setChangeMarks(editor, new TextRange(start, newEnd));
VimPlugin.getMark().setMark(editor, MarkGroup.MARK_CHANGE_POS, newEnd);
}
use of com.maddyhome.idea.vim.common.TextRange in project ideavim by JetBrains.
the class CopyGroup method putVisualRange.
public boolean putVisualRange(@NotNull Editor editor, @NotNull DataContext context, @NotNull TextRange range, int count, boolean indent, boolean cursorAfter) {
CommandState.SubMode subMode = CommandState.getInstance(editor).getSubMode();
Register reg = VimPlugin.getRegister().getLastRegister();
// Without this reset, the deleted text goes into the same register we just pasted from.
VimPlugin.getRegister().resetRegister();
if (reg != null) {
final SelectionType type = reg.getType();
if (type == SelectionType.LINE_WISE && editor.isOneLineMode()) {
return false;
}
int start = range.getStartOffset();
int end = range.getEndOffset();
int endLine = editor.offsetToLogicalPosition(end).line;
if (logger.isDebugEnabled()) {
logger.debug("start=" + start);
logger.debug("end=" + end);
}
if (subMode == CommandState.SubMode.VISUAL_LINE) {
range = new TextRange(range.getStartOffset(), Math.min(range.getEndOffset() + 1, EditorHelper.getFileSize(editor)));
}
VimPlugin.getChange().deleteRange(editor, range, SelectionType.fromSubMode(subMode), false);
editor.getCaretModel().moveToOffset(start);
int pos = start;
if (type == SelectionType.LINE_WISE) {
if (subMode == CommandState.SubMode.VISUAL_BLOCK) {
pos = editor.getDocument().getLineEndOffset(endLine) + 1;
} else if (subMode != CommandState.SubMode.VISUAL_LINE) {
editor.getDocument().insertString(start, "\n");
pos = start + 1;
}
} else if (type != SelectionType.CHARACTER_WISE) {
if (subMode == CommandState.SubMode.VISUAL_LINE) {
editor.getDocument().insertString(start, "\n");
}
}
putText(editor, context, pos, StringUtil.notNullize(reg.getText()), type, count, indent && type == SelectionType.LINE_WISE, cursorAfter, subMode);
return true;
}
return false;
}
use of com.maddyhome.idea.vim.common.TextRange in project ideavim by JetBrains.
the class CopyGroup method yankMotion.
/**
* This yanks the text moved over by the motion command argument.
*
* @param editor The editor to yank from
* @param context The data context
* @param count The number of times to yank
* @param rawCount The actual count entered by the user
* @param argument The motion command argument
* @return true if able to yank the text, false if not
*/
public boolean yankMotion(@NotNull Editor editor, DataContext context, int count, int rawCount, @NotNull Argument argument) {
TextRange range = MotionGroup.getMotionRange(editor, context, count, rawCount, argument, true);
final Command motion = argument.getMotion();
return motion != null && yankRange(editor, range, SelectionType.fromCommandFlags(motion.getFlags()), true);
}
use of com.maddyhome.idea.vim.common.TextRange in project ideavim by JetBrains.
the class SearchGroup method searchWord.
public int searchWord(@NotNull Editor editor, int count, boolean whole, int dir) {
TextRange range = SearchHelper.findWordUnderCursor(editor);
if (range == null) {
return -1;
}
StringBuilder pattern = new StringBuilder();
if (whole) {
pattern.append("\\<");
}
pattern.append(EditorHelper.getText(editor, range.getStartOffset(), range.getEndOffset()));
if (whole) {
pattern.append("\\>");
}
MotionGroup.moveCaret(editor, range.getStartOffset());
lastSearch = pattern.toString();
setLastPattern(editor, lastSearch);
lastOffset = "";
lastDir = dir;
searchHighlight(true);
return findItOffset(editor, editor.getCaretModel().getOffset(), count, lastDir, true);
}
Aggregations