public List<HighlightInfo> getHighlights() { clearLineMarkers(myEditor); final int count = myPairsToHighlight.size(); final List<HighlightInfo> highlightInfos = new ArrayList<HighlightInfo>(count * 2); final MarkupModel markupModel = myEditor.getMarkupModel(); final Color[] baseColors = XmlTagTreeHighlightingUtil.getBaseColors(); final Color[] colorsForEditor = count > 1 ? toColorsForEditor(baseColors) : new Color[] { myEditor .getColorsScheme() .getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES) .getBackgroundColor() }; final Color[] colorsForLineMarkers = toColorsForLineMarkers(baseColors); final List<RangeHighlighter> newHighlighters = new ArrayList<RangeHighlighter>(); assert colorsForEditor.length > 0; for (int i = 0; i < count && i < baseColors.length; i++) { Pair<TextRange, TextRange> pair = myPairsToHighlight.get(i); if (pair.first == null && pair.second == null) { continue; } Color color = colorsForEditor[i]; if (color == null) { continue; } if (pair.first != null && !pair.first.isEmpty()) { highlightInfos.add(createHighlightInfo(color, pair.first)); } if (pair.second != null && !pair.second.isEmpty()) { highlightInfos.add(createHighlightInfo(color, pair.second)); } final int start = pair.first != null ? pair.first.getStartOffset() : pair.second.getStartOffset(); final int end = pair.second != null ? pair.second.getEndOffset() : pair.first.getEndOffset(); final Color lineMarkerColor = colorsForLineMarkers[i]; if (count > 1 && lineMarkerColor != null && start != end) { final RangeHighlighter highlighter = createHighlighter(markupModel, new TextRange(start, end), lineMarkerColor); newHighlighters.add(highlighter); } } myEditor.putUserData(TAG_TREE_HIGHLIGHTERS_IN_EDITOR_KEY, newHighlighters); return highlightInfos; }
public void onContentChangedIn(EditorSource source) { myDiffUpdater.contentRemoved(source); final EditorEx editor = source.getEditor(); if (myIsHorizontal && source.getSide() == FragmentSide.SIDE1 && editor != null) { editor.setVerticalScrollbarOrientation(EditorEx.VERTICAL_SCROLLBAR_LEFT); } DiffSideView viewSide = getSideView(source.getSide()); viewSide.setEditorSource(getProject(), source); Disposer.dispose(myScrollSupport); if (editor == null) { if (!myDisposed) { rediff(); } return; } final MouseListener mouseListener = PopupHandler.installUnknownPopupHandler( editor.getContentComponent(), new MergeActionGroup(this, source.getSide()), ActionManager.getInstance()); myDiffUpdater.contentAdded(source); editor.getSettings().setLineNumbersShown(true); editor.getSettings().setFoldingOutlineShown(false); editor.getFoldingModel().setFoldingEnabled(false); ((EditorMarkupModel) editor.getMarkupModel()).setErrorStripeVisible(true); Editor editor1 = getEditor(FragmentSide.SIDE1); Editor editor2 = getEditor(FragmentSide.SIDE2); if (editor1 != null && editor2 != null && myIsSyncScroll) { myScrollSupport.install(new EditingSides[] {this}); } final VisibleAreaListener visibleAreaListener = mySplitter.getVisibleAreaListener(); final ScrollingModel scrollingModel = editor.getScrollingModel(); if (visibleAreaListener != null) { scrollingModel.addVisibleAreaListener(visibleAreaListener); scrollingModel.addVisibleAreaListener(myVisibleAreaListener); } myFontSizeSynchronizer.synchronize(editor); source.addDisposable( new Disposable() { public void dispose() { myFontSizeSynchronizer.stopSynchronize(editor); } }); source.addDisposable( new Disposable() { public void dispose() { if (visibleAreaListener != null) { scrollingModel.removeVisibleAreaListener(visibleAreaListener); scrollingModel.removeVisibleAreaListener(myVisibleAreaListener); } editor.getContentComponent().removeMouseListener(mouseListener); } }); }
@Override public void doApplyInformationToEditor() { final Long stamp = myEditor.getUserData(LAST_TIME_INDENTS_BUILT); if (stamp != null && stamp.longValue() == nowStamp()) return; List<RangeHighlighter> oldHighlighters = myEditor.getUserData(INDENT_HIGHLIGHTERS_IN_EDITOR_KEY); final List<RangeHighlighter> newHighlighters = new ArrayList<RangeHighlighter>(); final MarkupModel mm = myEditor.getMarkupModel(); int curRange = 0; if (oldHighlighters != null) { int curHighlight = 0; while (curRange < myRanges.size() && curHighlight < oldHighlighters.size()) { TextRange range = myRanges.get(curRange); RangeHighlighter highlighter = oldHighlighters.get(curHighlight); int cmp = compare(range, highlighter); if (cmp < 0) { newHighlighters.add(createHighlighter(mm, range)); curRange++; } else if (cmp > 0) { highlighter.dispose(); curHighlight++; } else { newHighlighters.add(highlighter); curHighlight++; curRange++; } } for (; curHighlight < oldHighlighters.size(); curHighlight++) { RangeHighlighter highlighter = oldHighlighters.get(curHighlight); highlighter.dispose(); } } final int startRangeIndex = curRange; assert myDocument != null; DocumentUtil.executeInBulk( myDocument, myRanges.size() > 10000, new Runnable() { @Override public void run() { for (int i = startRangeIndex; i < myRanges.size(); i++) { newHighlighters.add(createHighlighter(mm, myRanges.get(i))); } } }); myEditor.putUserData(INDENT_HIGHLIGHTERS_IN_EDITOR_KEY, newHighlighters); myEditor.putUserData(LAST_TIME_INDENTS_BUILT, nowStamp()); myEditor.getIndentsModel().assumeIndents(myDescriptors); }
protected void setTextToEditor(String text) { myEditor.getMarkupModel().removeAllHighlighters(); myEditor.getDocument().setText(text); ((EditorImpl) myEditor).resetSizes(); myEditor.getHighlighter().setText(text); if (myTextAttributes != null) { myEditor .getMarkupModel() .addRangeHighlighter( 0, myEditor.getDocument().getTextLength(), HighlighterLayer.ADDITIONAL_SYNTAX, myTextAttributes, HighlighterTargetArea.EXACT_RANGE); } ((EditorImpl) myEditor).setPaintSelection(mySelected); SelectionModel selectionModel = myEditor.getSelectionModel(); selectionModel.setSelection(0, mySelected ? myEditor.getDocument().getTextLength() : 0); }
@NotNull private MyGutterOperation createOperation(@NotNull Side side) { int offset = side.getStartOffset(myFragment); EditorEx editor = myViewer.getEditor(side); RangeHighlighter highlighter = editor .getMarkupModel() .addRangeHighlighter( offset, offset, HighlighterLayer.ADDITIONAL_SYNTAX, null, HighlighterTargetArea.LINES_IN_RANGE); return new MyGutterOperation(side, highlighter); }
@Nullable private MyGutterOperation createOperation(@NotNull ThreeSide side, @NotNull OperationType type) { if (isResolved(side)) return null; EditorEx editor = myViewer.getEditor(side); Document document = editor.getDocument(); int line = getStartLine(side); int offset = line == DiffUtil.getLineCount(document) ? document.getTextLength() : document.getLineStartOffset(line); RangeHighlighter highlighter = editor .getMarkupModel() .addRangeHighlighter( offset, offset, HighlighterLayer.ADDITIONAL_SYNTAX, null, HighlighterTargetArea.LINES_IN_RANGE); return new MyGutterOperation(side, highlighter, type); }
protected String addTextRangeToHistory( TextRange textRange, final EditorEx consoleEditor, boolean preserveMarkup) { final Document history = myHistoryViewer.getDocument(); final MarkupModel markupModel = DocumentMarkupModel.forDocument(history, myProject, true); if (myPrompt != null) { appendToHistoryDocument(history, myPrompt); } markupModel.addRangeHighlighter( history.getTextLength() - StringUtil.length(myPrompt), history.getTextLength(), HighlighterLayer.SYNTAX, ConsoleViewContentType.USER_INPUT.getAttributes(), HighlighterTargetArea.EXACT_RANGE); final int localStartOffset = textRange.getStartOffset(); String text; EditorHighlighter highlighter; if (consoleEditor instanceof EditorWindow) { EditorWindow editorWindow = (EditorWindow) consoleEditor; EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); PsiFile file = editorWindow.getInjectedFile(); final VirtualFile virtualFile = file.getVirtualFile(); assert virtualFile != null; highlighter = HighlighterFactory.createHighlighter(virtualFile, scheme, getProject()); String fullText = InjectedLanguageUtil.getUnescapedText(file, null, null); highlighter.setText(fullText); text = textRange.substring(fullText); } else { text = consoleEditor.getDocument().getText(textRange); highlighter = consoleEditor.getHighlighter(); } // offset can be changed after text trimming after insert due to buffer constraints appendToHistoryDocument(history, text); int offset = history.getTextLength() - text.length(); final HighlighterIterator iterator = highlighter.createIterator(localStartOffset); final int localEndOffset = textRange.getEndOffset(); while (!iterator.atEnd()) { final int itStart = iterator.getStart(); if (itStart > localEndOffset) break; final int itEnd = iterator.getEnd(); if (itEnd >= localStartOffset) { final int start = Math.max(itStart, localStartOffset) - localStartOffset + offset; final int end = Math.min(itEnd, localEndOffset) - localStartOffset + offset; markupModel.addRangeHighlighter( start, end, HighlighterLayer.SYNTAX, iterator.getTextAttributes(), HighlighterTargetArea.EXACT_RANGE); } iterator.advance(); } if (preserveMarkup) { duplicateHighlighters( markupModel, DocumentMarkupModel.forDocument(consoleEditor.getDocument(), myProject, true), offset, textRange); duplicateHighlighters(markupModel, consoleEditor.getMarkupModel(), offset, textRange); } if (!text.endsWith("\n")) { appendToHistoryDocument(history, "\n"); } return text; }