public void documentChanged(@NotNull DocumentEvent event) { if (!VimPlugin.isEnabled()) { return; } Project[] projs = ProjectManager.getInstance().getOpenProjects(); for (Project proj : projs) { Editor[] editors = EditorFactory.getInstance().getEditors(event.getDocument(), proj); for (Editor editor : editors) { Collection hls = EditorData.getLastHighlights(editor); if (hls == null) { continue; } int soff = event.getOffset(); int eoff = soff + event.getNewLength(); if (logger.isDebugEnabled()) { logger.debug("hls=" + hls); logger.debug("event=" + event); } Iterator iter = hls.iterator(); while (iter.hasNext()) { RangeHighlighter rh = (RangeHighlighter) iter.next(); if (!rh.isValid() || (eoff >= rh.getStartOffset() && soff <= rh.getEndOffset())) { iter.remove(); editor.getMarkupModel().removeHighlighter(rh); } } int sl = editor.offsetToLogicalPosition(soff).line; int el = editor.offsetToLogicalPosition(eoff).line; VimPlugin.getSearch().highlightSearchLines(editor, false, sl, el); hls = EditorData.getLastHighlights(editor); if (logger.isDebugEnabled()) { logger.debug("sl=" + sl + ", el=" + el); logger.debug("hls=" + hls); } } } }
private static void removeSearchHighlight(@NotNull Editor editor) { Collection<RangeHighlighter> ehl = EditorData.getLastHighlights(editor); if (ehl == null) { return; } for (RangeHighlighter rh : ehl) { editor.getMarkupModel().removeHighlighter(rh); } ehl.clear(); EditorData.setLastHighlights(editor, null); EditorData.setLastSearch(editor, null); }
private static void highlightSearchLines( @NotNull Editor editor, @NotNull String pattern, int startLine, int endLine, boolean ignoreCase) { final TextAttributes color = editor.getColorsScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); Collection<RangeHighlighter> highlighters = EditorData.getLastHighlights(editor); if (highlighters == null) { highlighters = new ArrayList<RangeHighlighter>(); EditorData.setLastHighlights(editor, highlighters); } for (TextRange range : findAll(editor, pattern, startLine, endLine, ignoreCase)) { final RangeHighlighter highlighter = highlightMatch(editor, range.getStartOffset(), range.getEndOffset()); highlighter.setErrorStripeMarkColor(color.getBackgroundColor()); highlighter.setErrorStripeTooltip(pattern); highlighters.add(highlighter); } }