private EditorHighlighter createHighlighter(LanguageFileType fileType) { // FileType fileType = FileTypeManager.getInstance().getFileTypeByExtension(""); // if (fileType == null) { // fileType = FileTypes.PLAIN_TEXT; // } SyntaxHighlighter originalHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, null, null); if (originalHighlighter == null) { originalHighlighter = new PlainSyntaxHighlighter(); } EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); LayeredLexerEditorHighlighter highlighter = new LayeredLexerEditorHighlighter(getFileHighlighter(fileType), scheme);// TODO: 2017/8/3 HTML highlighter.registerLayer(TextElementType, new LayerDescriptor(originalHighlighter, "")); return highlighter; }
private static int calcParensBalance(Document document, EditorHighlighter highlighter, int rangeStart, int rangeEnd){ LOG.assertTrue(0 <= rangeStart); LOG.assertTrue(rangeStart <= rangeEnd); LOG.assertTrue(rangeEnd <= document.getTextLength()); HighlighterIterator iterator = highlighter.createIterator(rangeStart); int balance = 0; while(!iterator.atEnd() && iterator.getStart() < rangeEnd){ IElementType tokenType = iterator.getTokenType(); if (tokenType == JavaTokenType.LPARENTH){ balance++; } else if (tokenType == JavaTokenType.RPARENTH){ balance--; } iterator.advance(); } return balance; }
public void testCpp() throws Exception { EditorHighlighter highlighter = HighlighterFactory.createHighlighter(getProject(), "A.cpp"); // 0123456789012345678 9 0123 45 6 7 highlighter.setText("#include try enum \"\\xff\\z\\\"xxx\""); HighlighterIterator iterator = highlighter.createIterator(2); assertEquals(CustomHighlighterTokenType.KEYWORD_1, iterator.getTokenType()); iterator = highlighter.createIterator(9); assertEquals(CustomHighlighterTokenType.KEYWORD_2, iterator.getTokenType()); iterator = highlighter.createIterator(15); assertEquals(CustomHighlighterTokenType.KEYWORD_1, iterator.getTokenType()); iterator = highlighter.createIterator(19); assertEquals(StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN, iterator.getTokenType()); iterator = highlighter.createIterator(23); assertEquals(StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN, iterator.getTokenType()); iterator = highlighter.createIterator(25); assertEquals(StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN, iterator.getTokenType()); iterator = highlighter.createIterator(27); assertEquals(CustomHighlighterTokenType.STRING, iterator.getTokenType()); }
@Nullable private EditorHighlighter buildHighlighter(@Nullable Project project, @NotNull DocumentContent content1, @NotNull DocumentContent content2, @NotNull CharSequence text1, @NotNull CharSequence text2, @NotNull List<HighlightRange> ranges, int textLength) { EditorHighlighter highlighter1 = DiffUtil.initEditorHighlighter(project, content1, text1); EditorHighlighter highlighter2 = DiffUtil.initEditorHighlighter(project, content2, text2); if (highlighter1 == null && highlighter2 == null) return null; if (highlighter1 == null) highlighter1 = DiffUtil.initEmptyEditorHighlighter(text1); if (highlighter2 == null) highlighter2 = DiffUtil.initEmptyEditorHighlighter(text2); return new UnifiedEditorHighlighter(myDocument, highlighter1, highlighter2, ranges, textLength); }
@NotNull @Override protected List<EditorHighlighterProvider> buildExtensions(@NotNull String stringKey, @NotNull final FileType key) { List<EditorHighlighterProvider> fromEP = super.buildExtensions(stringKey, key); if (fromEP.isEmpty()) { EditorHighlighterProvider defaultProvider = new EditorHighlighterProvider() { @Override public EditorHighlighter getEditorHighlighter(@Nullable Project project, @NotNull FileType fileType, @Nullable VirtualFile virtualFile, @NotNull EditorColorsScheme colors) { return EditorHighlighterFactory.getInstance().createEditorHighlighter( SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, project, virtualFile), colors); } }; return Collections.singletonList(defaultProvider); } return fromEP; }
private void setupHighlighterSettings(Editor left, Editor base, Editor right) { Editor[] editors = new Editor[]{left, base, right}; DiffContent[] contents = myData.getContents(); FileType[] types = DiffUtil.chooseContentTypes(contents); VirtualFile fallbackFile = contents[1].getFile(); FileType fallbackType = contents[1].getContentType(); for (int i = 0; i < 3; i++) { Editor editor = editors[i]; DiffContent content = contents[i]; EditorHighlighter highlighter = createHighlighter(types[i], content.getFile(), fallbackFile, fallbackType, myData.getProject()).createHighlighter(); if (highlighter != null) { ((EditorEx)editor).setHighlighter(highlighter); } } }
@Nullable public static EditorHighlighter getEditorHighlighterForCachesBuilding(Document document) { if (document == null) { return null; } final WeakReference<EditorHighlighter> editorHighlighterWeakReference = document.getUserData(ourSomeEditorSyntaxHighlighter); final EditorHighlighter someEditorHighlighter = SoftReference.dereference(editorHighlighterWeakReference); if (someEditorHighlighter instanceof LexerEditorHighlighter && ((LexerEditorHighlighter)someEditorHighlighter).isValid() ) { return someEditorHighlighter; } document.putUserData(ourSomeEditorSyntaxHighlighter, null); return null; }
@Nullable public static Lexer getLexerBasedOnLexerHighlighter(CharSequence text, VirtualFile virtualFile, Project project) { EditorHighlighter highlighter = null; PsiFile psiFile = virtualFile != null ? PsiManager.getInstance(project).findFile(virtualFile) : null; final Document document = psiFile != null ? PsiDocumentManager.getInstance(project).getDocument(psiFile) : null; final EditorHighlighter cachedEditorHighlighter; boolean alreadyInitializedHighlighter = false; if (document != null && (cachedEditorHighlighter = getEditorHighlighterForCachesBuilding(document)) != null && PlatformIdTableBuilding.checkCanUseCachedEditorHighlighter(text, cachedEditorHighlighter)) { highlighter = cachedEditorHighlighter; alreadyInitializedHighlighter = true; } else if (virtualFile != null) { highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(project, virtualFile); } if (highlighter != null) { return new LexerEditorHighlighterLexer(highlighter, alreadyInitializedHighlighter); } return null; }
private static Editor createEditor(boolean isReadOnly, final Document document, final Project project) { EditorFactory editorFactory = EditorFactory.getInstance(); Editor editor = (isReadOnly ? editorFactory.createViewer(document, project) : editorFactory.createEditor(document, project)); editor.getContentComponent().setFocusable(!isReadOnly); EditorSettings editorSettings = editor.getSettings(); editorSettings.setVirtualSpace(false); editorSettings.setLineMarkerAreaShown(false); editorSettings.setIndentGuidesShown(false); editorSettings.setLineNumbersShown(false); editorSettings.setFoldingOutlineShown(false); editorSettings.setCaretRowShown(false); EditorColorsScheme scheme = editor.getColorsScheme(); VirtualFile file = FileDocumentManager.getInstance().getFile(document); if (file != null) { EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(file, scheme, project); ((EditorEx) editor).setHighlighter(highlighter); } return editor; }
@Override public void updateView() { EditorColorsScheme scheme = myOptions.getSelectedScheme(); myEditor.setColorsScheme(scheme); EditorHighlighter highlighter = null; if (myPage instanceof EditorHighlightingProvidingColorSettingsPage) { highlighter = ((EditorHighlightingProvidingColorSettingsPage)myPage).createEditorHighlighter(scheme); } if (highlighter == null) { final SyntaxHighlighter pageHighlighter = myPage.getHighlighter(); highlighter = HighlighterFactory.createHighlighter(pageHighlighter, scheme); } myEditor.setHighlighter(highlighter); updateHighlighters(); myEditor.reinitSettings(); }
@Override public void beforeCharDeleted(char c, PsiFile file, Editor editor) { if (c != '{') return; if (!(file instanceof GroovyFile)) return; final int offset = editor.getCaretModel().getOffset(); final EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter(); if (offset < 1) return; HighlighterIterator iterator = highlighter.createIterator(offset); if (iterator.getTokenType() != GroovyTokenTypes.mRCURLY) return; iterator.retreat(); if (iterator.getStart() < 1 || iterator.getTokenType() != GroovyTokenTypes.mLCURLY) return; editor.getDocument().deleteString(offset, offset + 1); }
TodoTreeBuilder(JTree tree, DefaultTreeModel treeModel, Project project) { super(tree, treeModel, null, MyComparator.ourInstance, false); myProject = project; myFileTree = new FileTree(); myDirtyFileSet = new HashSet<VirtualFile>(); myFile2Highlighter = new HashMap<VirtualFile, EditorHighlighter>(); PsiManager psiManager = PsiManager.getInstance(myProject); mySearchHelper = PsiTodoSearchHelper.SERVICE.getInstance(myProject); psiManager.addPsiTreeChangeListener(new MyPsiTreeChangeListener()); myFileStatusListener = new MyFileStatusListener(); setCanYieldUpdate(true); }
private EditorHighlighter createHighlighter() { if (myTemplate != null && myVelocityFileType != FileTypes.UNKNOWN) { return EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, new LightVirtualFile("aaa." + myTemplate.getExtension() + ".ft")); } FileType fileType = null; if (myTemplate != null) { fileType = FileTypeManager.getInstance().getFileTypeByExtension(myTemplate.getExtension()); } if (fileType == null) { fileType = FileTypes.PLAIN_TEXT; } SyntaxHighlighter originalHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, null, null); if (originalHighlighter == null) { originalHighlighter = new PlainSyntaxHighlighter(); } final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); LayeredLexerEditorHighlighter highlighter = new LayeredLexerEditorHighlighter(new TemplateHighlighter(), scheme); highlighter.registerLayer(FileTemplateTokenType.TEXT, new LayerDescriptor(originalHighlighter, "")); return highlighter; }
/** * Force re-highlighting in all open editors that belong to specified project. */ public static void rehighlightOpenEditors(final @NotNull Project project) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { for (Editor editor : EditorFactory.getInstance().getAllEditors()) { if (editor instanceof EditorEx && editor.getProject() == project) { final VirtualFile vFile = ((EditorEx)editor).getVirtualFile(); if (vFile != null) { final EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(project, vFile); ((EditorEx)editor).setHighlighter(highlighter); } } } } }); }
@Override public Result charTyped(char c, Project project, @NotNull Editor editor, @NotNull PsiFile file) { if (c != '{' || project == null || !HandlerUtils.canBeInvoked(editor, project)) { return Result.CONTINUE; } if (!(file instanceof GroovyFile)) return Result.CONTINUE; int caret = editor.getCaretModel().getOffset(); final EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter(); if (caret < 1) return Result.CONTINUE; HighlighterIterator iterator = highlighter.createIterator(caret - 1); if (iterator.getTokenType() != GroovyTokenTypes.mLCURLY) return Result.CONTINUE; iterator.retreat(); if (iterator.atEnd() || iterator.getTokenType() != GroovyTokenTypes.mDOLLAR) return Result.CONTINUE; iterator.advance(); if (iterator.atEnd()) return Result.CONTINUE; iterator.advance(); if (iterator.getTokenType() != GroovyTokenTypes.mGSTRING_BEGIN) return Result.CONTINUE; editor.getDocument().insertString(caret, "}"); return Result.STOP; }
private static boolean handleBetweenSquareBraces(Editor editor, int caret, DataContext context, Project project, EditorActionHandler originalHandler) { String text = editor.getDocument().getText(); if (text == null || text.isEmpty()) return false; final EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter(); if (caret < 1 || caret > text.length() - 1) { return false; } HighlighterIterator iterator = highlighter.createIterator(caret - 1); if (GroovyTokenTypes.mLBRACK == iterator.getTokenType()) { if (text.length() > caret) { iterator = highlighter.createIterator(caret); if (GroovyTokenTypes.mRBRACK == iterator.getTokenType()) { originalHandler.execute(editor, context); originalHandler.execute(editor, context); editor.getCaretModel().moveCaretRelatively(0, -1, false, false, true); insertSpacesByGroovyContinuationIndent(editor, project); return true; } } } return false; }
private void updatePreviewHighlighter(EditorEx editor) { EditorColorsScheme scheme = editor.getColorsScheme(); editor.getSettings().setCaretRowShown(false); EditorHighlighter highlighter = this.createHighlighter(scheme); if (highlighter != null) { editor.setHighlighter(highlighter); } }
@Override public EditorHighlighter getEditorHighlighter(@Nullable Project project, @NotNull FileType type, @Nullable VirtualFile file, @NotNull EditorColorsScheme scheme) { return new RythmLayeredSyntaxHighlighter(project, scheme, type, file); }
@Override public EditorHighlighter getEditorHighlighter(@Nullable Project project, @NotNull FileType type, @Nullable VirtualFile file, @NotNull EditorColorsScheme scheme) { return new JetLayeredSyntaxHighlighter(project, scheme, type, file); }
private static int getExistingRParenthOffset(final Editor editor, final int tailOffset) { final Document document = editor.getDocument(); if (tailOffset >= document.getTextLength()) return -1; final CharSequence charsSequence = document.getCharsSequence(); EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter(); int existingRParenthOffset = -1; for(HighlighterIterator iterator = highlighter.createIterator(tailOffset); !iterator.atEnd(); iterator.advance()){ final IElementType tokenType = iterator.getTokenType(); if ((!(tokenType instanceof IJavaElementType) || !ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(tokenType)) && tokenType != TokenType.WHITE_SPACE) { final int start = iterator.getStart(); if (iterator.getEnd() == start + 1 && ')' == charsSequence.charAt(start)) { existingRParenthOffset = start; } break; } } if (existingRParenthOffset >= 0){ final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(editor.getProject()); psiDocumentManager.commitDocument(document); TextRange range = getRangeToCheckParensBalance(psiDocumentManager.getPsiFile(document), document, editor.getCaretModel().getOffset()); int balance = calcParensBalance(document, highlighter, range.getStartOffset(), range.getEndOffset()); if (balance > 0){ return -1; } } return existingRParenthOffset; }
public void testHaskel() throws Exception { EditorHighlighter highlighter = HighlighterFactory.createHighlighter(getProject(), "A.hs"); // 0123456789012345678 9 0123 45 6 7 highlighter.setText("{-# #-} module"); HighlighterIterator iterator = highlighter.createIterator(2); assertEquals(CustomHighlighterTokenType.MULTI_LINE_COMMENT, iterator.getTokenType()); iterator = highlighter.createIterator(12); assertEquals(CustomHighlighterTokenType.KEYWORD_1, iterator.getTokenType()); }
public void testBrokenText() { myFixture.configureByText("a.java", "import java.util.ArrayList;" + "class A {" + " ArrayList<caret><String"); final Editor editor = myFixture.getEditor(); final EditorHighlighter editorHighlighter = ((EditorEx)editor).getHighlighter(); final HighlighterIterator iterator = editorHighlighter.createIterator(editor.getCaretModel().getOffset()); boolean matched = BraceMatchingUtil.matchBrace(editor.getDocument().getCharsSequence(), myFixture.getFile().getFileType(), iterator, true); assertFalse(matched); }
public void testBinaryStatement() { myFixture.configureByText("a.java", "import java.util.ArrayList;" + "class A {" + " int i = 3 <caret>< 4 ? 5 > 6 : 1 : 1 : 1;" + "}"); final Editor editor = myFixture.getEditor(); final EditorHighlighter editorHighlighter = ((EditorEx)editor).getHighlighter(); final HighlighterIterator iterator = editorHighlighter.createIterator(editor.getCaretModel().getOffset()); boolean matched = BraceMatchingUtil.matchBrace(editor.getDocument().getCharsSequence(), myFixture.getFile().getFileType(), iterator, true); assertFalse(matched); }
public TwosideDocumentData(@NotNull UnifiedFragmentBuilder builder, @Nullable EditorHighlighter highlighter, @Nullable UnifiedEditorRangeHighlighter rangeHighlighter) { myBuilder = builder; myHighlighter = highlighter; myRangeHighlighter = rangeHighlighter; }
public CombinedEditorData(@NotNull CharSequence text, @Nullable EditorHighlighter highlighter, @Nullable UnifiedEditorRangeHighlighter rangeHighlighter, @Nullable FileType fileType, @NotNull TIntFunction convertor1, @NotNull TIntFunction convertor2) { myText = text; myHighlighter = highlighter; myRangeHighlighter = rangeHighlighter; myFileType = fileType; myLineConvertor1 = convertor1; myLineConvertor2 = convertor2; }
public UnifiedEditorHighlighter(@NotNull Document document, @NotNull EditorHighlighter highlighter1, @NotNull EditorHighlighter highlighter2, @NotNull List<HighlightRange> ranges, int textLength) { myDocument = document; myPieces = new ArrayList<Element>(); init(highlighter1.createIterator(0), highlighter2.createIterator(0), ranges, textLength); }
@Nullable public static EditorHighlighter initEditorHighlighter(@Nullable Project project, @NotNull DocumentContent content, @NotNull CharSequence text) { EditorHighlighter highlighter = createEditorHighlighter(project, content); if (highlighter == null) return null; highlighter.setText(text); return highlighter; }
@Nullable public static EditorHighlighter createEditorHighlighter(@Nullable Project project, @NotNull DocumentContent content) { FileType type = content.getContentType(); VirtualFile file = content.getHighlightFile(); if ((file != null && file.getFileType() == type) || file instanceof LightVirtualFile) { return EditorHighlighterFactory.getInstance().createEditorHighlighter(project, file); } if (type != null) { return EditorHighlighterFactory.getInstance().createEditorHighlighter(project, type); } return null; }
public static boolean checkCanUseCachedEditorHighlighter(final CharSequence chars, final EditorHighlighter editorHighlighter) { assert editorHighlighter instanceof LexerEditorHighlighter; final boolean b = ((LexerEditorHighlighter)editorHighlighter).checkContentIsEqualTo(chars); if (!b) { final Logger logger = Logger.getInstance(IdTableBuilding.class.getName()); logger.warn("Unexpected mismatch of editor highlighter content with indexing content"); } return b; }
public static List<IElementType> getAllTokens(EditorHighlighter highlighter) { List<IElementType> tokens = new ArrayList<IElementType>(); HighlighterIterator iterator = highlighter.createIterator(0); while (!iterator.atEnd()) { tokens.add(iterator.getTokenType()); iterator.advance(); } return tokens; }
@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); ((EditorEx)editor).setContextMenuGroupId(IdeActions.GROUP_EDITOR_POPUP); ((EditorImpl) editor).setDropHandler(new FileDropHandler(editor)); TextEditorProvider.putTextEditor(editor, myTextEditor); return editor; }
/** * Updates editors' highlighters. This should be done when the opened file * changes its file type. */ private void updateHighlighters(){ if (!myProject.isDisposed() && !myEditor.isDisposed()) { final EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, myFile); ((EditorEx)myEditor).setHighlighter(highlighter); } }
private void applyHighlighter() { EditorEx editor = myEditorSource.getEditor(); if (editor == null) return; EditorHighlighter highlighter = myHighlighterFactory.createHighlighter(); if (highlighter != null) editor.setHighlighter(highlighter); editor.getSettings().setCaretRowShown(false); }
public EditorHighlighter createHighlighter() { if (myFileType == null || myProject == null) return null; if ((myFile != null && myFile.getFileType() == myFileType) || myFile instanceof LightVirtualFile) { return EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, myFile); } return EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, myFileType); }
/** * Finds out whether there's a boundary between two lexemes of different type at given offset. */ public static boolean isLexemeBoundary(@NotNull Editor editor, int offset) { if (!(editor instanceof EditorEx) || offset <= 0 || offset >= editor.getDocument().getTextLength()) return false; if (CharArrayUtil.isEmptyOrSpaces(editor.getDocument().getImmutableCharSequence(), offset - 1, offset + 1)) return false; EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter(); HighlighterIterator it = highlighter.createIterator(offset); if (it.getStart() != offset) { return false; } IElementType rightToken = it.getTokenType(); it.retreat(); IElementType leftToken = it.getTokenType(); return !Comparing.equal(leftToken, rightToken); }
private void paintBorderEffect(Graphics2D g, ClipDetector clipDetector, EditorHighlighter highlighter, int clipStartOffset, int clipEndOffset) { HighlighterIterator it = highlighter.createIterator(clipStartOffset); while (!it.atEnd() && it.getStart() < clipEndOffset) { TextAttributes attributes = it.getTextAttributes(); if (isBorder(attributes)) { paintBorderEffect(g, clipDetector, it.getStart(), it.getEnd(), attributes); } it.advance(); } }
public void paintHighlighters(EditorHighlighter highlighter) { int startOffset = startOfLineByOffset(myStartOffset); if (startOffset < 0 || startOffset >= myEditor.getDocument().getTextLength()) return; RangeIterator iterator = new RangeIterator(new FoldingOrNewLineGaps(myEditor), SAME_COLOR_BOXES, highlighter.createIterator(startOffset), BOX_FILTER); iterator.init(myRange); while (!iterator.atEnd()) { iterator.advance(); paintBorder(myGraphics, myEditor, iterator.getStart(), iterator.getEnd(), iterator.getTextAttributes().getEffectColor(), iterator.getTextAttributes().getEffectType()); } }
@NotNull private static Pair<JComponent, Integer> createEditorComponent(@NotNull Range range, @NotNull Editor editor, @NotNull LineStatusTracker tracker, @Nullable List<DiffFragment> wordDiff) { if (range.getType() == Range.INSERTED) return Pair.create(null, 0); DocumentEx doc = (DocumentEx)tracker.getVcsDocument(); EditorEx uEditor = (EditorEx)EditorFactory.getInstance().createViewer(doc, tracker.getProject()); uEditor.setColorsScheme(editor.getColorsScheme()); FileType fileType = tracker.getVirtualFile().getFileType(); DiffUtil.setEditorCodeStyle(tracker.getProject(), uEditor, fileType); EditorHighlighterFactory highlighterFactory = EditorHighlighterFactory.getInstance(); EditorHighlighter highlighter = highlighterFactory.createEditorHighlighter(tracker.getProject(), getFileName(tracker.getDocument())); uEditor.setHighlighter(highlighter); if (wordDiff != null) { int vcsStartShift = tracker.getVcsTextRange(range).getStartOffset(); for (DiffFragment fragment : wordDiff) { int vcsStart = vcsStartShift + fragment.getStartOffset1(); int vcsEnd = vcsStartShift + fragment.getEndOffset1(); TextDiffType type = getDiffType(fragment); DiffDrawUtil.createInlineHighlighter(uEditor, vcsStart, vcsEnd, type); } } JComponent fragmentComponent = EditorFragmentComponent.createEditorFragmentComponent(uEditor, range.getVcsLine1(), range.getVcsLine2(), false, false); int leftBorder = fragmentComponent.getBorder().getBorderInsets(fragmentComponent).left; EditorFactory.getInstance().releaseEditor(uEditor); return Pair.create(fragmentComponent, leftBorder); }
@Override @Nullable protected EditorHighlighter createHighlighter(final EditorColorsScheme scheme) { FileType fileType = getFileType(); return FileTypeEditorHighlighterProviders.INSTANCE.forFileType(fileType).getEditorHighlighter( ProjectUtil.guessCurrentProject(getPanel()), fileType, null, scheme); }
@Override public Editor openTextEditor(@NotNull OpenFileDescriptor descriptor, boolean focusEditor) { final VirtualFile file = descriptor.getFile(); Editor editor = myVirtualFile2Editor.get(file); if (editor == null) { PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file); LOG.assertTrue(psiFile != null, file); Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiFile); LOG.assertTrue(document != null, psiFile); editor = EditorFactory.getInstance().createEditor(document, myProject); final EditorHighlighter highlighter = HighlighterFactory.createHighlighter(myProject, file); ((EditorEx) editor).setHighlighter(highlighter); ((EditorEx) editor).setFile(file); myVirtualFile2Editor.put(file, editor); } if (descriptor.getOffset() >= 0){ editor.getCaretModel().moveToOffset(descriptor.getOffset()); } else if (descriptor.getLine() >= 0 && descriptor.getColumn() >= 0){ editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(descriptor.getLine(), descriptor.getColumn())); } editor.getSelectionModel().removeSelection(); myActiveFile = file; return editor; }