private Document findDocument() { Editor editor = ResourceToManifoldUtil.getActiveEditor( getProject() ); if( editor instanceof EditorImpl ) { EditorImpl editorImpl = (EditorImpl)editor; if( editorImpl.getVirtualFile().getPath().equals( _file.getVirtualFile().getPath() ) ) { // get document from current editor return editorImpl.getDocument(); } } // get document from file return _file.getViewProvider().getDocument(); }
@NotNull protected static Editor configureFromFileTextWithoutPSI(@NonNls @NotNull final String fileText) { return new WriteCommandAction<Editor>(null) { @Override protected void run(@NotNull Result<Editor> result) throws Throwable { final Document fakeDocument = EditorFactory.getInstance().createDocument(fileText); EditorTestUtil.CaretAndSelectionState caretsState = EditorTestUtil.extractCaretAndSelectionMarkers(fakeDocument); String newFileText = fakeDocument.getText(); Document document = EditorFactory.getInstance().createDocument(newFileText); final Editor editor = EditorFactory.getInstance().createEditor(document); ((EditorImpl)editor).setCaretActive(); EditorTestUtil.setCaretsAndSelection(editor, caretsState); result.setResult(editor); } }.execute().getResultObject(); }
public static void moveCaretRelativelyAndScroll(@NotNull Editor editor, int columnShift, int lineShift, boolean withSelection) { Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); VisualPosition pos = editor.getCaretModel().getVisualPosition(); Point caretLocation = editor.visualPositionToXY(pos); int caretVShift = caretLocation.y - visibleArea.y; editor.getCaretModel().moveCaretRelatively(columnShift, lineShift, withSelection, false, false); VisualPosition caretPos = editor.getCaretModel().getVisualPosition(); Point caretLocation2 = editor.visualPositionToXY(caretPos); final boolean scrollToCaret = !(editor instanceof EditorImpl) || ((EditorImpl)editor).isScrollToCaret(); if (scrollToCaret) { editor.getScrollingModel().scrollVertically(caretLocation2.y - caretVShift); } }
@Override public void execute(Editor editor, DataContext dataContext) { editor.getCaretModel().removeSecondaryCarets(); int offset = editor.getDocument().getTextLength(); if (editor instanceof EditorImpl && ((EditorImpl)editor).myUseNewRendering) { editor.getCaretModel().moveToLogicalPosition(editor.offsetToLogicalPosition(offset).leanForward(true)); } else { editor.getCaretModel().moveToOffset(offset); } editor.getSelectionModel().removeSelection(); ScrollingModel scrollingModel = editor.getScrollingModel(); scrollingModel.disableAnimation(); scrollingModel.scrollToCaret(ScrollType.CENTER); scrollingModel.enableAnimation(); Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project != null) { IdeDocumentHistory instance = IdeDocumentHistory.getInstance(project); if (instance != null) { instance.includeCurrentCommandAsNavigation(); } } }
private int visualLineStartOffset(int offset, boolean leanForward) { EditorImpl editor = myView.getEditor(); int result = EditorUtil.getNotFoldedLineStartOffset(editor, offset); SoftWrapModelImpl softWrapModel = editor.getSoftWrapModel(); List<? extends SoftWrap> softWraps = softWrapModel.getRegisteredSoftWraps(); int currentOrPrevWrapIndex = softWrapModel.getSoftWrapIndex(offset); SoftWrap currentOrPrevWrap; if (currentOrPrevWrapIndex < 0) { currentOrPrevWrapIndex = - currentOrPrevWrapIndex - 2; currentOrPrevWrap = currentOrPrevWrapIndex < 0 || currentOrPrevWrapIndex >= softWraps.size() ? null : softWraps.get(currentOrPrevWrapIndex); } else { currentOrPrevWrap = leanForward ? softWraps.get(currentOrPrevWrapIndex) : null; } if (currentOrPrevWrap != null && currentOrPrevWrap.getStart() > result) { result = currentOrPrevWrap.getStart(); } return result; }
public EditorView(EditorImpl editor) { myFontRenderContext = createFontRenderContext(); myEditor = editor; myDocument = editor.getDocument(); myPainter = new EditorPainter(this); myMapper = new EditorCoordinateMapper(this); mySizeManager = new EditorSizeManager(this); myTextLayoutCache = new TextLayoutCache(this); myLogicalPositionCache = new LogicalPositionCache(this); myTabFragment = new TabFragment(this); Disposer.register(this, myLogicalPositionCache); Disposer.register(this, myTextLayoutCache); Disposer.register(this, mySizeManager); }
private IncrementalCacheUpdateEvent(@NotNull Document document, int startOffset, int oldEndOffset, int newEndOffset, @NotNull CachingSoftWrapDataMapper mapper, @NotNull EditorImpl editor) { myStartOffset = editor.myUseNewRendering ? editor.visualLineStartOffset(editor.offsetToVisualLine(startOffset) - 1) : mapper.getPreviousVisualLineStartOffset(startOffset); myMandatoryEndOffset = newEndOffset; myLengthDiff = newEndOffset - oldEndOffset; myStartLogicalPosition = editor.myUseNewRendering ? editor.offsetToLogicalPosition(myStartOffset) : mapper.offsetToLogicalPosition(myStartOffset); if (editor.myUseNewRendering) { myStartVisualPosition = editor.logicalToVisualPosition(myStartLogicalPosition); } else { LOG.assertTrue(myStartLogicalPosition.visualPositionAware); myStartVisualPosition = myStartLogicalPosition.toVisualPosition(); } myOldEndLogicalLine = document.getLineNumber(oldEndOffset); }
/** * Every soft wrap implies that multiple visual positions correspond to the same document offset. We can classify * such positions by the following criteria: * <pre> * <ul> * <li>positions from visual line with soft wrap start;</li> * <li>positions from visual line with soft wrap end;</li> * </ul> * </pre> * <p/> * This method allows to answer if caret offset of the given editor points to soft wrap and visual caret position * belongs to the visual line where soft wrap end is located. * * @param editor target editor * @return <code>true</code> if caret offset of the given editor points to visual position that belongs to * visual line where soft wrap end is located */ public static boolean isCaretAfterSoftWrap(CaretImpl caret) { if (!caret.isUpToDate()) { return false; } EditorImpl editor = caret.getEditor(); SoftWrapModel softWrapModel = editor.getSoftWrapModel(); int offset = caret.getOffset(); SoftWrap softWrap = softWrapModel.getSoftWrap(offset); if (softWrap == null) { return false; } if (editor.myUseNewRendering) { VisualPosition afterWrapPosition = editor.offsetToVisualPosition(offset, false, false); VisualPosition caretPosition = caret.getVisualPosition(); return caretPosition.line == afterWrapPosition.line && caretPosition.column <= afterWrapPosition.column; } else { return editor.offsetToVisualLine(offset) == caret.getVisualPosition().line; } }
@Override public Dimension getPreferredSize() { if (myPreferredSize == null) { int maxLineLength = 0; int linesCount = 0; for (LineTokenizer lt = new LineTokenizer(myRawText); !lt.atEnd(); lt.advance()) { maxLineLength = Math.max(maxLineLength, lt.getLength()); linesCount++; } FontMetrics fontMetrics = ((EditorImpl)getEditor()).getFontMetrics(myTextAttributes != null ? myTextAttributes.getFontType() : Font.PLAIN); int preferredHeight = getEditor().getLineHeight() * Math.max(1, linesCount); int preferredWidth = fontMetrics.charWidth('m') * maxLineLength; Insets insets = getInsets(); if (insets != null) { preferredHeight += insets.top + insets.bottom; preferredWidth += insets.left + insets.right; } myPreferredSize = new Dimension(preferredWidth, preferredHeight); } return myPreferredSize; }
public void testSoftWrapsRecalculationOnTabWidthChange() throws IOException { // Inspired by IDEA-78616 - the point is to recalculate soft wraps when tab width is changed. String text = "\t<caret> my text"; // Build soft wraps cache. init(40, text); VisualPosition caretPositionBefore = getEditor().getCaretModel().getVisualPosition(); // Change tab size. final CommonCodeStyleSettings.IndentOptions indentOptions = getCurrentCodeStyleSettings().getIndentOptions(); assertNotNull(indentOptions); indentOptions.TAB_SIZE++; ((EditorImpl)getEditor()).reinitSettings(); assertEquals( new VisualPosition(caretPositionBefore.line, caretPositionBefore.column + 1), getEditor().getCaretModel().getVisualPosition() ); }
static void setOrRefreshErrorStripeRenderer(@NotNull EditorMarkupModel editorMarkupModel, @NotNull Project project, @NotNull Document document, PsiFile file) { ApplicationManager.getApplication().assertIsDispatchThread(); if (!editorMarkupModel.isErrorStripeVisible() || !DaemonCodeAnalyzer.getInstance(project).isHighlightingAvailable(file)) { return; } ErrorStripeRenderer renderer = editorMarkupModel.getErrorStripeRenderer(); if (renderer instanceof TrafficLightRenderer) { TrafficLightRenderer tlr = (TrafficLightRenderer)renderer; tlr.refresh(); ((EditorMarkupModelImpl)editorMarkupModel).repaintVerticalScrollBar(); if (tlr.myFile == null || tlr.myFile.isValid()) return; Disposer.dispose(tlr); } EditorImpl editor = (EditorImpl)editorMarkupModel.getEditor(); if (!editor.isDisposed()) { renderer = new TrafficLightRenderer(project, document, file); Disposer.register(editor.getDisposable(), (Disposable)renderer); editorMarkupModel.setErrorStripeRenderer(renderer); } }
public ConsoleGutterComponent(@NotNull Editor editor, @NotNull GutterContentProvider gutterContentProvider, boolean atLineStart) { this.editor = (EditorImpl)editor; this.gutterContentProvider = gutterContentProvider; this.atLineStart = atLineStart; if (atLineStart) { setOpaque(gutterContentProvider.getLineStartGutterOverlap(editor) == 0); } else { addListeners(); setOpaque(false); } int spaceWidth = EditorUtil.getSpaceWidth(Font.PLAIN, editor); // at line start: icon/one-char symbol + space gap = atLineStart ? spaceWidth * GutterContentProvider.MAX_LINE_END_GUTTER_WIDTH_IN_CHAR : spaceWidth; maxContentWidth = atLineStart ? gap : 0; }
@NotNull public static Editor getInjectedEditorForInjectedFile(@NotNull Editor hostEditor, @NotNull Caret hostCaret, @Nullable final PsiFile injectedFile) { if (injectedFile == null || hostEditor instanceof EditorWindow || hostEditor.isDisposed()) return hostEditor; Project project = hostEditor.getProject(); if (project == null) project = injectedFile.getProject(); Document document = PsiDocumentManager.getInstance(project).getDocument(injectedFile); if (!(document instanceof DocumentWindowImpl)) return hostEditor; DocumentWindowImpl documentWindow = (DocumentWindowImpl)document; if (hostCaret.hasSelection()) { int selstart = hostCaret.getSelectionStart(); if (selstart != -1) { int selend = Math.max(selstart, hostCaret.getSelectionEnd()); if (!documentWindow.containsRange(selstart, selend)) { // selection spreads out the injected editor range return hostEditor; } } } if (!documentWindow.isValid()) { return hostEditor; // since the moment we got hold of injectedFile and this moment call, document may have been dirtied } return EditorWindowImpl.create(documentWindow, (EditorImpl)hostEditor, injectedFile); }
public static Editor openEditorFor(@NotNull PsiFile file, @NotNull Project project) { Document document = PsiDocumentManager.getInstance(project).getDocument(file); // may return editor injected in current selection in the host editor, not for the file passed as argument VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile == null) { return null; } if (virtualFile instanceof VirtualFileWindow) { virtualFile = ((VirtualFileWindow)virtualFile).getDelegate(); } Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile, -1), false); if (editor == null || editor instanceof EditorWindow || editor.isDisposed()) return editor; if (document instanceof DocumentWindowImpl) { return EditorWindowImpl.create((DocumentWindowImpl)document, (EditorImpl)editor, file); } return editor; }
public static Editor create(@NotNull final DocumentWindowImpl documentRange, @NotNull final EditorImpl editor, @NotNull final PsiFile injectedFile) { assert documentRange.isValid(); assert injectedFile.isValid(); EditorWindowImpl window; synchronized (allEditors) { for (EditorWindowImpl editorWindow : allEditors) { if (editorWindow.getDocument() == documentRange && editorWindow.getDelegate() == editor) { editorWindow.myInjectedFile = injectedFile; if (editorWindow.isValid()) { return editorWindow; } } if (editorWindow.getDocument().areRangesEqual(documentRange)) { //int i = 0; } } window = new EditorWindowImpl(documentRange, editor, injectedFile, documentRange.isOneLine()); allEditors.add(window); } assert window.isValid(); return window; }
@Override public void templateFinished(Template template, final boolean brokenOff) { boolean bind = false; try { super.templateFinished(template, brokenOff); if (!brokenOff) { bind = performRefactoring(); } else { performCleanup(); } moveOffsetAfter(!brokenOff); } finally { if (!bind) { try { ((EditorImpl)InjectedLanguageUtil.getTopLevelEditor(myEditor)).stopDumbLater(); } finally { FinishMarkAction.finish(myProject, myEditor, myMarkAction); if (myBeforeRevert != null) { myBeforeRevert.dispose(); } } } } }
/** * @return created editor. This editor should be released by {@link #disposeEditor(Editor) } * method. */ @NotNull private Editor createEditor(){ Editor editor = EditorFactory.getInstance().createEditor(myDocument, myProject); ((EditorMarkupModel) editor.getMarkupModel()).setErrorStripeVisible(true); EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(myFile, EditorColorsManager.getInstance().getGlobalScheme(), myProject); ((EditorEx) editor).setHighlighter(highlighter); ((EditorEx) editor).setFile(myFile); editor.addEditorMouseListener(myEditorMouseListener); ((EditorImpl) editor).setDropHandler(new FileDropHandler(editor)); TextEditorProvider.putTextEditor(editor, myTextEditor); return editor; }
public static void moveCaretRelativelyAndScroll(Editor editor, int columnShift, int lineShift, boolean withSelection) { Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); VisualPosition pos = editor.getCaretModel().getVisualPosition(); Point caretLocation = editor.visualPositionToXY(pos); int caretVShift = caretLocation.y - visibleArea.y; editor.getCaretModel().moveCaretRelatively(columnShift, lineShift, withSelection, false, false); //editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); VisualPosition caretPos = editor.getCaretModel().getVisualPosition(); Point caretLocation2 = editor.visualPositionToXY(caretPos); final boolean scrollToCaret = !(editor instanceof EditorImpl) || ((EditorImpl)editor).isScrollToCaret(); if (scrollToCaret) { editor.getScrollingModel().scrollVertically(caretLocation2.y - caretVShift); } }
public static void setOrRefreshErrorStripeRenderer(@NotNull EditorMarkupModel editorMarkupModel, @NotNull Project project, @NotNull Document document, PsiFile file) { ApplicationManager.getApplication().assertIsDispatchThread(); if (!editorMarkupModel.isErrorStripeVisible() || !DaemonCodeAnalyzer.getInstance(project).isHighlightingAvailable(file)) { return; } ErrorStripeRenderer renderer = editorMarkupModel.getErrorStripeRenderer(); if (renderer instanceof TrafficLightRenderer) { TrafficLightRenderer tlr = (TrafficLightRenderer)renderer; tlr.refresh(); ((EditorMarkupModelImpl)editorMarkupModel).repaintVerticalScrollBar(); if (tlr.myFile == null || tlr.myFile.isValid()) return; Disposer.dispose(tlr); } renderer = new TrafficLightRenderer(project, document, file); Disposer.register(((EditorImpl)editorMarkupModel.getEditor()).getDisposable(), (Disposable)renderer); editorMarkupModel.setErrorStripeRenderer(renderer); }
@NotNull public static Editor getInjectedEditorForInjectedFile(@NotNull Editor hostEditor, @Nullable final PsiFile injectedFile) { if (injectedFile == null || hostEditor instanceof EditorWindow || hostEditor.isDisposed()) return hostEditor; Project project = hostEditor.getProject(); if (project == null) project = injectedFile.getProject(); Document document = PsiDocumentManager.getInstance(project).getDocument(injectedFile); if (!(document instanceof DocumentWindowImpl)) return hostEditor; DocumentWindowImpl documentWindow = (DocumentWindowImpl)document; SelectionModel selectionModel = hostEditor.getSelectionModel(); if (selectionModel.hasSelection()) { int selstart = selectionModel.getSelectionStart(); int selend = selectionModel.getSelectionEnd(); if (!documentWindow.containsRange(selstart, selend)) { // selection spreads out the injected editor range return hostEditor; } } if (!documentWindow.isValid()) return hostEditor; // since the moment we got hold of injectedFile and this moment call, document may have been dirtied return EditorWindow.create(documentWindow, (EditorImpl)hostEditor, injectedFile); }
public static Editor openEditorFor(@NotNull PsiFile file, @NotNull Project project) { Document document = PsiDocumentManager.getInstance(project).getDocument(file); // may return editor injected in current selection in the host editor, not for the file passed as argument VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile == null) { return null; } if (virtualFile instanceof VirtualFileWindow) { virtualFile = ((VirtualFileWindow)virtualFile).getDelegate(); } Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile, -1), false); if (editor == null || editor instanceof EditorWindow || editor.isDisposed()) return editor; if (document instanceof DocumentWindowImpl) { return EditorWindow.create((DocumentWindowImpl)document, (EditorImpl)editor, file); } return editor; }
public static Editor create(@NotNull final DocumentWindowImpl documentRange, @NotNull final EditorImpl editor, @NotNull final PsiFile injectedFile) { assert documentRange.isValid(); assert injectedFile.isValid(); EditorWindow window; synchronized (allEditors) { for (EditorWindow editorWindow : allEditors) { if (editorWindow.getDocument() == documentRange && editorWindow.getDelegate() == editor) { editorWindow.myInjectedFile = injectedFile; if (editorWindow.isValid()) { return editorWindow; } } if (editorWindow.getDocument().areRangesEqual(documentRange)) { //int i = 0; } } window = new EditorWindow(documentRange, editor, injectedFile, documentRange.isOneLine()); allEditors.add(window); } assert window.isValid(); return window; }
@Override public void templateFinished(Template template, final boolean brokenOff) { boolean bind = false; try { super.templateFinished(template, brokenOff); if (!brokenOff) { bind = performRefactoring(); } moveOffsetAfter(!brokenOff); } finally { if (!bind) { try { ((EditorImpl)InjectedLanguageUtil.getTopLevelEditor(myEditor)).stopDumbLater(); } finally { FinishMarkAction.finish(myProject, myEditor, myMarkAction); if (myBeforeRevert != null) { myBeforeRevert.dispose(); } } } } }
private void updateUI(final Editor editor, boolean moveCaretToStart) { final TextRange range = getCurrentSignatureTextRange(); final int start = range.getStartOffset(); final int end = range.getEndOffset(); final int startLine = ((EditorImpl)editor).offsetToLogicalPosition(start, false).line; final int endLine = ((EditorImpl)editor).offsetToLogicalPosition(end, false).line; final int lineCount = Math.max(1, endLine - startLine); final Dimension old = getSize(); final Dimension size = new Dimension(getWidth(), editor.getLineHeight() * (lineCount + 2) + 4); if (!old.equals(size)) { setSize(size); setPreferredSize(size); revalidate(); repaint(); } if (moveCaretToStart) { editor.getCaretModel().moveToOffset(start); } editor.getScrollingModel().scrollVertically((startLine - 1)* editor.getLineHeight() + 2); }
public static void moveCaretRelativelyAndScroll(@Nonnull Editor editor, int columnShift, int lineShift, boolean withSelection) { Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); VisualPosition pos = editor.getCaretModel().getVisualPosition(); Point caretLocation = editor.visualPositionToXY(pos); int caretVShift = caretLocation.y - visibleArea.y; editor.getCaretModel().moveCaretRelatively(columnShift, lineShift, withSelection, false, false); VisualPosition caretPos = editor.getCaretModel().getVisualPosition(); Point caretLocation2 = editor.visualPositionToXY(caretPos); final boolean scrollToCaret = !(editor instanceof EditorImpl) || ((EditorImpl)editor).isScrollToCaret(); if (scrollToCaret) { editor.getScrollingModel().scrollVertically(caretLocation2.y - caretVShift); } }
@Override public void execute(Editor editor, DataContext dataContext) { editor.getCaretModel().removeSecondaryCarets(); int offset = editor.getDocument().getTextLength(); if (editor instanceof EditorImpl) { editor.getCaretModel().moveToLogicalPosition(editor.offsetToLogicalPosition(offset).leanForward(true)); } else { editor.getCaretModel().moveToOffset(offset); } editor.getSelectionModel().removeSelection(); ScrollingModel scrollingModel = editor.getScrollingModel(); scrollingModel.disableAnimation(); scrollingModel.scrollToCaret(ScrollType.CENTER); scrollingModel.enableAnimation(); Project project = dataContext.getData(CommonDataKeys.PROJECT); if (project != null) { IdeDocumentHistory instance = IdeDocumentHistory.getInstance(project); if (instance != null) { instance.includeCurrentCommandAsNavigation(); } } }
private int visualLineStartOffset(int offset, boolean leanForward) { EditorImpl editor = myView.getEditor(); offset = DocumentUtil.alignToCodePointBoundary(myDocument, offset); int result = EditorUtil.getNotFoldedLineStartOffset(editor, offset); SoftWrapModelImpl softWrapModel = editor.getSoftWrapModel(); List<? extends SoftWrap> softWraps = softWrapModel.getRegisteredSoftWraps(); int currentOrPrevWrapIndex = softWrapModel.getSoftWrapIndex(offset); SoftWrap currentOrPrevWrap; if (currentOrPrevWrapIndex < 0) { currentOrPrevWrapIndex = - currentOrPrevWrapIndex - 2; currentOrPrevWrap = currentOrPrevWrapIndex < 0 || currentOrPrevWrapIndex >= softWraps.size() ? null : softWraps.get(currentOrPrevWrapIndex); } else { currentOrPrevWrap = leanForward ? softWraps.get(currentOrPrevWrapIndex) : null; } if (currentOrPrevWrap != null && currentOrPrevWrap.getStart() > result) { result = currentOrPrevWrap.getStart(); } return result; }
public EditorView(EditorImpl editor) { myEditor = editor; myDocument = editor.getDocument(); myPainter = new EditorPainter(this); myMapper = new EditorCoordinateMapper(this); mySizeManager = new EditorSizeManager(this); myTextLayoutCache = new TextLayoutCache(this); myLogicalPositionCache = new LogicalPositionCache(this); myTabFragment = new TabFragment(this); myEditor.getContentComponent().addHierarchyListener(this); myEditor.getScrollingModel().addVisibleAreaListener(this); Disposer.register(this, myLogicalPositionCache); Disposer.register(this, myTextLayoutCache); Disposer.register(this, mySizeManager); }
private static VisualLineInfo getVisualLineInfo(@Nonnull EditorImpl editor, int offset, boolean beforeSoftWrap) { Document document = editor.getDocument(); int textLength = document.getTextLength(); if (offset <= 0 || textLength == 0) return new VisualLineInfo(0, false); offset = Math.min(offset, textLength); int startOffset = EditorUtil.getNotFoldedLineStartOffset(editor, offset); SoftWrapModelImpl softWrapModel = editor.getSoftWrapModel(); int wrapIndex = softWrapModel.getSoftWrapIndex(offset); int prevSoftWrapIndex = wrapIndex < 0 ? (- wrapIndex - 2) : wrapIndex - (beforeSoftWrap ? 1 : 0); SoftWrap prevSoftWrap = prevSoftWrapIndex < 0 ? null : softWrapModel.getRegisteredSoftWraps().get(prevSoftWrapIndex); int visualLineStartOffset = prevSoftWrap == null ? startOffset : Math.max(startOffset, prevSoftWrap.getStart()); return new VisualLineInfo(visualLineStartOffset, prevSoftWrap != null && prevSoftWrap.getStart() == visualLineStartOffset); }
@RequiredDispatchThread static void setOrRefreshErrorStripeRenderer(@Nonnull EditorMarkupModel editorMarkupModel, @Nonnull Project project, @Nonnull Document document, PsiFile file) { ApplicationManager.getApplication().assertIsDispatchThread(); if (!editorMarkupModel.isErrorStripeVisible() || !DaemonCodeAnalyzer.getInstance(project).isHighlightingAvailable(file)) { return; } ErrorStripeRenderer renderer = editorMarkupModel.getErrorStripeRenderer(); if (renderer instanceof TrafficLightRenderer) { TrafficLightRenderer tlr = (TrafficLightRenderer)renderer; tlr.refresh(); ((EditorMarkupModelImpl)editorMarkupModel).repaintVerticalScrollBar(); if (tlr.myFile == null || tlr.myFile.isValid()) return; Disposer.dispose(tlr); } EditorImpl editor = (EditorImpl)editorMarkupModel.getEditor(); if (!editor.isDisposed()) { renderer = new TrafficLightRenderer(project, document, file); Disposer.register(editor.getDisposable(), (Disposable)renderer); editorMarkupModel.setErrorStripeRenderer(renderer); } }
void updatePreview(@Nullable LookupElement item) { if (!Registry.is("ide.lookup.preview.insertion")) return; myInlays.forEach(Disposer::dispose); myInlays.clear(); String suffix = getSuffixText(item); Editor editor = myLookup.getTopLevelEditor(); if (!suffix.isEmpty() && editor instanceof EditorImpl && !editor.getSelectionModel().hasSelection() && InplaceRefactoring.getActiveInplaceRenamer(editor) == null) { myLookup.performGuardedChange(() -> { for (Caret caret : editor.getCaretModel().getAllCarets()) { ensureCaretBeforeInlays(caret); addInlay(suffix, caret.getOffset()); } }); } }
public ConsoleGutterComponent(@Nonnull Editor editor, @Nonnull GutterContentProvider gutterContentProvider, boolean atLineStart) { this.editor = (EditorImpl)editor; this.gutterContentProvider = gutterContentProvider; this.atLineStart = atLineStart; if (atLineStart) { setOpaque(gutterContentProvider.getLineStartGutterOverlap(editor) == 0); } else { addListeners(); setOpaque(false); } int spaceWidth = EditorUtil.getSpaceWidth(Font.PLAIN, editor); // at line start: icon/one-char symbol + space gap = atLineStart ? spaceWidth * GutterContentProvider.MAX_LINE_END_GUTTER_WIDTH_IN_CHAR : spaceWidth; maxContentWidth = atLineStart ? gap : 0; }
@Nonnull static Editor create(@Nonnull final DocumentWindowImpl documentRange, @Nonnull final EditorImpl editor, @Nonnull final PsiFile injectedFile) { assert documentRange.isValid(); assert injectedFile.isValid(); EditorWindowImpl window; synchronized (allEditors) { for (EditorWindowImpl editorWindow : allEditors) { if (editorWindow.getDocument() == documentRange && editorWindow.getDelegate() == editor) { editorWindow.myInjectedFile = injectedFile; if (editorWindow.isValid()) { return editorWindow; } } if (editorWindow.getDocument().areRangesEqual(documentRange)) { //int i = 0; } } window = new EditorWindowImpl(documentRange, editor, injectedFile, documentRange.isOneLine()); allEditors.add(window); } assert window.isValid(); return window; }
private EditorWindowImpl(@Nonnull DocumentWindowImpl documentWindow, @Nonnull final EditorImpl delegate, @Nonnull PsiFile injectedFile, boolean oneLine) { myDocumentWindow = documentWindow; myDelegate = delegate; myInjectedFile = injectedFile; myOneLine = oneLine; myCaretModelDelegate = new CaretModelWindow(myDelegate.getCaretModel(), this); mySelectionModelDelegate = new SelectionModelWindow(myDelegate, myDocumentWindow,this); myMarkupModelDelegate = new MarkupModelWindow(myDelegate.getMarkupModel(), myDocumentWindow); myDocumentMarkupModelDelegate = new MarkupModelWindow(myDelegate.getFilteredDocumentMarkupModel(), myDocumentWindow); myFoldingModelWindow = new FoldingModelWindow(delegate.getFoldingModel(), documentWindow, this); mySoftWrapModel = new SoftWrapModelWindow(); myInlayModel = new InlayModelWindow(); }
@Nonnull public static Editor getInjectedEditorForInjectedFile(@Nonnull Editor hostEditor, @Nonnull Caret hostCaret, @Nullable final PsiFile injectedFile) { if (injectedFile == null || hostEditor instanceof EditorWindow || hostEditor.isDisposed()) return hostEditor; Project project = hostEditor.getProject(); if (project == null) project = injectedFile.getProject(); Document document = PsiDocumentManager.getInstance(project).getDocument(injectedFile); if (!(document instanceof DocumentWindowImpl)) return hostEditor; DocumentWindowImpl documentWindow = (DocumentWindowImpl)document; if (hostCaret.hasSelection()) { int selstart = hostCaret.getSelectionStart(); if (selstart != -1) { int selend = Math.max(selstart, hostCaret.getSelectionEnd()); if (!documentWindow.containsRange(selstart, selend)) { // selection spreads out the injected editor range return hostEditor; } } } if (!documentWindow.isValid()) { return hostEditor; // since the moment we got hold of injectedFile and this moment call, document may have been dirtied } return EditorWindowImpl.create(documentWindow, (EditorImpl)hostEditor, injectedFile); }
public static Editor openEditorFor(@Nonnull PsiFile file, @Nonnull Project project) { Document document = PsiDocumentManager.getInstance(project).getDocument(file); // may return editor injected in current selection in the host editor, not for the file passed as argument VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile == null) { return null; } if (virtualFile instanceof VirtualFileWindow) { virtualFile = ((VirtualFileWindow)virtualFile).getDelegate(); } Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile, -1), false); if (editor == null || editor instanceof EditorWindow || editor.isDisposed()) return editor; if (document instanceof DocumentWindowImpl) { return EditorWindowImpl.create((DocumentWindowImpl)document, (EditorImpl)editor, file); } return editor; }