Search in sources :

Example 31 with TextRange

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

Example 32 with TextRange

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

Example 33 with TextRange

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

Example 34 with TextRange

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

Example 35 with TextRange

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;
}
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