com.intellij.openapi.editor.Editor.getSelectionModel()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(155)

本文整理了Java中com.intellij.openapi.editor.Editor.getSelectionModel()方法的一些代码示例,展示了Editor.getSelectionModel()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Editor.getSelectionModel()方法的具体详情如下:
包路径:com.intellij.openapi.editor.Editor
类名称:Editor
方法名:getSelectionModel

Editor.getSelectionModel介绍

暂无

代码示例

代码示例来源:origin: JetBrains/ideavim

public void addEditorSelectionListener(@NotNull Editor editor, @NotNull SelectionListener listener) {
 editor.getSelectionModel().addSelectionListener(listener);
}

代码示例来源:origin: JetBrains/ideavim

public void removeEditorSelectionListener(@NotNull Editor editor, @NotNull SelectionListener listener) {
 editor.getSelectionModel().removeSelectionListener(listener);
}

代码示例来源:origin: JetBrains/ideavim

@NotNull
public TextRange getVisualRange(@NotNull Editor editor) {
 return new TextRange(editor.getSelectionModel().getBlockSelectionStarts(),
   editor.getSelectionModel().getBlockSelectionEnds());
}

代码示例来源:origin: JetBrains/ideavim

public void autoIndentRange(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context,
              @NotNull TextRange range) {
 final int startOffset = EditorHelper.getLineStartForOffset(editor, range.getStartOffset());
 final int endOffset = EditorHelper.getLineEndForOffset(editor, range.getEndOffset());
 editor.getSelectionModel().setSelection(startOffset, endOffset);
 KeyHandler.executeAction("AutoIndentLines", context);
 final int firstLine = editor.offsetToLogicalPosition(Math.min(startOffset, endOffset)).line;
 final int newOffset = VimPlugin.getMotion().moveCaretToLineStartSkipLeading(editor, firstLine);
 MotionGroup.moveCaret(editor, caret, newOffset);
 restoreCursor(editor, caret, caret.getLogicalPosition().line);
}

代码示例来源:origin: hsz/idea-gitignore

/**
 * Handles QuickFix action invoked on {@link IgnoreSyntax}.
 *
 * @param project      the {@link Project} containing the working file
 * @param file         the {@link PsiFile} containing handled entry
 * @param startElement the {@link IgnoreSyntax} that will be selected and replaced
 * @param endElement   the {@link PsiElement} which is ignored in invoked action
 */
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file,
          @Nullable("is null when called from inspection") Editor editor,
          @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
  if (startElement instanceof IgnoreSyntax) {
    PsiElement value = ((IgnoreSyntax) startElement).getValue();
    if (editor != null) {
      editor.getSelectionModel().setSelection(
          value.getTextOffset(),
          value.getTextOffset() + value.getTextLength()
      );
    }
    new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(project, editor);
  }
}

代码示例来源:origin: JetBrains/ideavim

public void mouseDragged(@NotNull EditorMouseEvent event) {
 if (!VimPlugin.isEnabled()) return;
 if (event.getArea() == EditorMouseEventArea.EDITING_AREA ||
   event.getArea() != EditorMouseEventArea.ANNOTATIONS_AREA) {
  if (dragEditor == null) {
   if (event.getArea() == EditorMouseEventArea.EDITING_AREA) {
    mode = CommandState.SubMode.VISUAL_CHARACTER;
   }
   else if (event.getArea() != EditorMouseEventArea.ANNOTATIONS_AREA) {
    mode = CommandState.SubMode.VISUAL_LINE;
   }
   startOff = event.getEditor().getSelectionModel().getSelectionStart();
   endOff = event.getEditor().getSelectionModel().getSelectionEnd();
  }
  dragEditor = event.getEditor();
 }
}

代码示例来源:origin: JetBrains/ideavim

public void assertSelection(@Nullable String expected) {
 final String selected = myFixture.getEditor().getSelectionModel().getSelectedText();
 assertEquals(expected, selected);
}

代码示例来源:origin: hsz/idea-gitignore

Editor[] editors = EditorFactory.getInstance().getEditors(document);
if (editors.length > 0) {
  VisualPosition position = editors[0].getSelectionModel().getSelectionStartPosition();
  if (position != null) {
    offset = document.getLineStartOffset(position.line);

代码示例来源:origin: JetBrains/ideavim

public void selectionChanged(@NotNull SelectionEvent selectionEvent) {
  final Editor editor = selectionEvent.getEditor();
  final Document document = editor.getDocument();
  if (myMakingChanges || (document instanceof DocumentEx && ((DocumentEx) document).isInEventsHandling())) {
   return;
  }
  myMakingChanges = true;
  try {
   final com.intellij.openapi.util.TextRange newRange = selectionEvent.getNewRange();
   for (Editor e : EditorFactory.getInstance().getEditors(document)) {
    if (!e.equals(editor)) {
     e.getSelectionModel().setSelection(newRange.getStartOffset(), newRange.getEndOffset());
    }
   }
  } finally {
   myMakingChanges = false;
  }
 }
}

代码示例来源:origin: JetBrains/ideavim

@NotNull
private LineRange getLineRange(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context,
                @NotNull ExCommand cmd) {
 final LineRange range = cmd.getLineRange(editor, caret, context);
 final LineRange normalizedRange;
 // Something like "30,20sort" gets converted to "20,30sort"
 if (range.getEndLine() < range.getStartLine()) {
  normalizedRange = new LineRange(range.getEndLine(), range.getStartLine());
 }
 else {
  normalizedRange = range;
 }
 // If we don't have a range, we either have "sort", a selection, or a block
 if (normalizedRange.getEndLine() - normalizedRange.getStartLine() == 0) {
  // If we have a selection.
  final SelectionModel selectionModel = editor.getSelectionModel();
  if (selectionModel.hasSelection()) {
   final int start = selectionModel.getSelectionStart();
   final int end = selectionModel.getSelectionEnd();
   final int startLine = editor.offsetToLogicalPosition(start).line;
   final int endLine = editor.offsetToLogicalPosition(end).line;
   return new LineRange(startLine, endLine);
  }
  // If we have a generic selection, i.e. "sort" entire document
  else {
   return new LineRange(0, editor.getDocument().getLineCount() - 1);
  }
 }
 return normalizedRange;
}

代码示例来源:origin: JetBrains/ideavim

public static void moveCaret(@NotNull Editor editor, @NotNull Caret caret, int offset, boolean forceKeepVisual) {
 if (offset >= 0 && offset <= editor.getDocument().getTextLength()) {
  final boolean keepVisual = forceKeepVisual || keepVisual(editor);
  if (caret.getOffset() != offset) {
   caret.moveToOffset(offset);
   CaretData.setLastColumn(editor, caret, caret.getVisualPosition().column);
   if (caret == editor.getCaretModel().getPrimaryCaret()) {
    scrollCaretIntoView(editor);
   }
  }
  if (keepVisual) {
   VimPlugin.getMotion().updateSelection(editor, caret, offset);
  }
  else {
   editor.getSelectionModel().removeSelection();
  }
 }
}

代码示例来源:origin: JetBrains/ideavim

int start = editor.getSelectionModel().getSelectionStart();
int end = editor.getSelectionModel().getSelectionEnd();
editor.getSelectionModel().setSelection(start, Math.max(start, end - 1));

代码示例来源:origin: JetBrains/ideavim

private void processMouseReleased(@NotNull Editor editor, @NotNull CommandState.SubMode mode, int startOff,
                 int endOff) {
 if (ExEntryPanel.getInstance().isActive()) {
  ExEntryPanel.getInstance().deactivate(false);
 }
 ExOutputModel.getInstance(editor).clear();
 if (CommandState.getInstance(editor).getMode() == CommandState.Mode.VISUAL) {
  CommandState.getInstance(editor).popState();
 }
 int start = editor.getSelectionModel().getSelectionStart();
 int end = editor.getSelectionModel().getSelectionEnd();
 if (start == end) return;
 if (mode == CommandState.SubMode.VISUAL_LINE) {
  end--;
  endOff--;
 }
 if (end == startOff || end == endOff) {
  int t = start;
  start = end;
  end = t;
  if (mode == CommandState.SubMode.VISUAL_CHARACTER) {
   start--;
  }
 }
 MotionGroup.moveCaret(editor, editor.getCaretModel().getPrimaryCaret(), start);
 toggleVisual(editor, 1, 0, mode);
 MotionGroup.moveCaret(editor, editor.getCaretModel().getPrimaryCaret(), end);
 KeyHandler.getInstance().reset(editor);
}

代码示例来源:origin: JetBrains/ideavim

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;
  editor.getSelectionModel().removeSelection();
  return;

代码示例来源:origin: hsz/idea-gitignore

/**
 * Handles an action of adding new template.
 * Ignores action if selected file is not a {@link IgnoreFile} instance, otherwise shows GeneratorDialog.
 *
 * @param e action event
 */
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
  final Project project = e.getData(CommonDataKeys.PROJECT);
  final PsiFile file = e.getData(CommonDataKeys.PSI_FILE);
  if (project == null || !(file instanceof IgnoreFile)) {
    return;
  }
  String content = file.getText();
  Document document = file.getViewProvider().getDocument();
  if (document != null) {
    Editor[] editors = EditorFactory.getInstance().getEditors(document);
    if (editors.length > 0) {
      String selectedText = editors[0].getSelectionModel().getSelectedText();
      if (!StringUtil.isEmpty(selectedText)) {
        content = selectedText;
      }
    }
  }
  new UserTemplateDialog(project, content).show();
}

代码示例来源:origin: JetBrains/ideavim

int start = editor.getSelectionModel().getSelectionStart();
int end = editor.getSelectionModel().getSelectionEnd();
editor.getSelectionModel().setSelection(start, Math.max(start, end - 1));

代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin

protected static void performAction(GoIntroduceOperation operation) {
 SelectionModel selectionModel = operation.getEditor().getSelectionModel();
 boolean hasSelection = selectionModel.hasSelection();
 GoExpression expression =

代码示例来源:origin: JetBrains/ideavim

private void updateBlockSelection(@NotNull Editor editor, int offset) {
 EditorData.setVisualBlockEnd(editor, offset);
 EditorData.setVisualBlockOffset(editor, offset);
 int start = EditorData.getVisualBlockStart(editor);
 int end = EditorData.getVisualBlockEnd(editor);
 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 (CaretData.getLastColumn(editor.getCaretModel().getPrimaryCaret()) >= MotionGroup.LAST_COLUMN) {
   caret.setSelection(caret.getSelectionStart(), lineEndOffset);
  }
  if (!EditorHelper.isLineEmpty(editor, line, false)) {
   caret.moveToOffset(caret.getSelectionEnd() - 1);
  }
 }
 editor.getCaretModel().getPrimaryCaret().moveToOffset(end);
 VimPlugin.getMark().setVisualSelectionMarks(editor, new TextRange(start, end));
}

代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin

@NotNull
protected PsiElement findElementAtCaretOrInSelection() {
 SelectionModel selectionModel = myFixture.getEditor().getSelectionModel();
 if (selectionModel.hasSelection()) {
  PsiElement left = myFixture.getFile().findElementAt(selectionModel.getSelectionStart());
  PsiElement right = myFixture.getFile().findElementAt(selectionModel.getSelectionEnd() - 1);
  assertNotNull(left);
  assertNotNull(right);
  return ObjectUtils.assertNotNull(PsiTreeUtil.findCommonParent(left, right));
 }
 else {
  return ObjectUtils.assertNotNull(myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset()));
 }
}

代码示例来源:origin: JetBrains/ideavim

CommandState.getInstance(editor).pushState(CommandState.Mode.VISUAL, mode, MappingMode.VISUAL);
if (mode == CommandState.SubMode.VISUAL_BLOCK) {
 EditorData.setVisualBlockStart(editor, editor.getSelectionModel().getSelectionStart());
 updateBlockSelection(editor, editor.getSelectionModel().getSelectionEnd());
 MotionGroup
   .moveCaret(editor, editor.getCaretModel().getPrimaryCaret(), EditorData.getVisualBlockEnd(editor), true);

相关文章