Search in sources :

Example 36 with TextRange

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);
    }
}
Also used : TextRange(com.maddyhome.idea.vim.common.TextRange)

Example 37 with 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);
}
Also used : TextRange(com.maddyhome.idea.vim.common.TextRange)

Example 38 with TextRange

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;
}
Also used : Register(com.maddyhome.idea.vim.common.Register) SelectionType(com.maddyhome.idea.vim.command.SelectionType) CommandState(com.maddyhome.idea.vim.command.CommandState) TextRange(com.maddyhome.idea.vim.common.TextRange)

Example 39 with TextRange

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);
}
Also used : Command(com.maddyhome.idea.vim.command.Command) TextRange(com.maddyhome.idea.vim.common.TextRange)

Example 40 with TextRange

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);
}
Also used : TextRange(com.maddyhome.idea.vim.common.TextRange)

Aggregations

TextRange (com.maddyhome.idea.vim.common.TextRange)46 Nullable (org.jetbrains.annotations.Nullable)8 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)2 CharacterPosition (com.maddyhome.idea.vim.common.CharacterPosition)2 Register (com.maddyhome.idea.vim.common.Register)2 RegExp (com.maddyhome.idea.vim.regexp.RegExp)2 Document (com.intellij.openapi.editor.Document)1 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)1 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)1 FileType (com.intellij.openapi.fileTypes.FileType)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)1 MotionEditorAction (com.maddyhome.idea.vim.action.motion.MotionEditorAction)1 TextObjectAction (com.maddyhome.idea.vim.action.motion.TextObjectAction)1 Command (com.maddyhome.idea.vim.command.Command)1 CommandState (com.maddyhome.idea.vim.command.CommandState)1 SelectionType (com.maddyhome.idea.vim.command.SelectionType)1 Mark (com.maddyhome.idea.vim.common.Mark)1 SearchHelper (com.maddyhome.idea.vim.helper.SearchHelper)1