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(); } } }
editor.getSelectionModel().removeSelection(); return;
void modifySelection(TextRange textRange, SelectionModel model) { model.removeSelection(); }
/** * {@link com.intellij.codeInsight.highlighting.HighlightUsagesHandler#handleNoUsageTargets(PsiFile, * Editor, SelectionModel, Project)} */ private static void handleNoUsageTargets(PsiFile file, @NotNull Editor editor, @NotNull Project project) { if (file.findElementAt(editor.getCaretModel().getOffset()) instanceof PsiWhiteSpace) { return; } final SelectionModel selectionModel = editor.getSelectionModel(); selectionModel.selectWordAtCaret(false); String selection = selectionModel.getSelectedText(); // LOG.assertTrue(selection != null); if (selection != null) { for (int i = 0; i < selection.length(); i++) { if (!Character.isJavaIdentifierPart(selection.charAt(i))) { selectionModel.removeSelection(); } } searchSelection(editor, project); selectionModel.removeSelection(); } }
@Override public void updateView(@NotNull List<NamedTextAttr> namedTextAttrList) { UIUtil.invokeLaterIfNeeded(() -> { if (myEditor.isDisposed()) { return; } myEditor.getMarkupModel().removeAllHighlighters(); myEditor.getSelectionModel().removeSelection(); if (namedTextAttrList.isEmpty()) { ApplicationManager.getApplication().runWriteAction(() -> { myEditor.getDocument().setText(""); }); return; } StringBuilder sb = new StringBuilder(); for (NamedTextAttr namedTextAttr : namedTextAttrList) { sb.append(namedTextAttr.getName()).append("\n"); } ApplicationManager.getApplication().runWriteAction(() -> { myEditor.getDocument().setText(sb.toString()); }); int size = namedTextAttrList.size(); for (int i = 0; i < size; i++) { highlightLine(i, namedTextAttrList.get(i)); } }); }
private void onClick(MouseEvent e) { if (highlightSource) { TreePath path = myTree.getClosestPathForLocation(e.getX(), e.getY()); if (path == null) { return; } DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Tree tree = (Tree) node.getUserObject(); int startIndex; int stopIndex; if (tree instanceof ParserRuleContext) { startIndex = ((ParserRuleContext) tree).getStart().getStartIndex(); stopIndex = ((ParserRuleContext) tree).getStop().getStopIndex(); } else if (tree instanceof TerminalNode) { startIndex = ((TerminalNode) tree).getSymbol().getStartIndex(); stopIndex = ((TerminalNode) tree).getSymbol().getStopIndex(); } else { return; } Editor editor = previewPanel.inputPanel.getInputEditor(); editor.getSelectionModel().removeSelection(); editor.getSelectionModel().setSelection(startIndex, stopIndex + 1); } } }