Java Code Examples for com.intellij.openapi.editor.ex.EditorEx#setHighlighter()

The following examples show how to use com.intellij.openapi.editor.ex.EditorEx#setHighlighter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DetailViewImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
protected Editor createEditor(@Nullable Project project, Document document, VirtualFile file) {
  EditorEx editor = (EditorEx)EditorFactory.getInstance().createViewer(document, project);

  final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
  EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(file, scheme, project);

  editor.setFile(file);
  editor.setHighlighter(highlighter);

  EditorSettings settings = editor.getSettings();
  settings.setAnimatedScrolling(false);
  settings.setRefrainFromScrolling(false);
  settings.setLineNumbersShown(true);
  settings.setFoldingOutlineShown(false);
  if (settings instanceof SettingsImpl) {
    ((SettingsImpl)settings).setSoftWrapAppliancePlace(SoftWrapAppliancePlaces.PREVIEW);
  }
  editor.getFoldingModel().setFoldingEnabled(false);

  return editor;
}
 
Example 2
Source File: DesktopTextEditorImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
protected Runnable loadEditorInBackground() {
  EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
  EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(myFile, scheme, myProject);
  EditorEx editor = (EditorEx)getEditor();
  highlighter.setText(editor.getDocument().getImmutableCharSequence());
  return () -> editor.setHighlighter(highlighter);
}
 
Example 3
Source File: DiffSideView.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void applyHighlighter() {
  EditorEx editor = myEditorSource.getEditor();
  if (editor == null) return;
  EditorHighlighter highlighter = myHighlighterFactory.createHighlighter();
  if (highlighter != null) editor.setHighlighter(highlighter);
  editor.getColorsScheme().setColor(EditorColors.CARET_ROW_COLOR, null);
}
 
Example 4
Source File: LineStatusMarkerPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private EditorFragmentComponent createEditorComponent(@Nullable FileType fileType, @javax.annotation.Nullable List<DiffFragment> wordDiff) {
  if (myRange.getType() == Range.INSERTED) return null;

  EditorEx uEditor = (EditorEx)EditorFactory.getInstance().createViewer(myTracker.getVcsDocument(), myTracker.getProject());
  uEditor.setColorsScheme(myEditor.getColorsScheme());

  DiffUtil.setEditorCodeStyle(myTracker.getProject(), uEditor, fileType);

  EditorHighlighterFactory highlighterFactory = EditorHighlighterFactory.getInstance();
  uEditor.setHighlighter(highlighterFactory.createEditorHighlighter(myTracker.getProject(), getFileName(myTracker.getDocument())));

  if (wordDiff != null) {
    int vcsStartShift = myTracker.getVcsTextRange(myRange).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);
    }
  }

  EditorFragmentComponent fragmentComponent =
          EditorFragmentComponent.createEditorFragmentComponent(uEditor, myRange.getVcsLine1(), myRange.getVcsLine2(), false, false);

  EditorFactory.getInstance().releaseEditor(uEditor);

  return fragmentComponent;
}
 
Example 5
Source File: LanguageTextField.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected EditorEx createEditor() {
  final EditorEx ex = super.createEditor();

  if (myLanguage != null) {
    final FileType fileType = myLanguage.getAssociatedFileType();
    ex.setHighlighter(HighlighterFactory.createHighlighter(myProject, fileType));
  }
  ex.setEmbeddedIntoDialogWrapper(true);

  return ex;
}
 
Example 6
Source File: MethodSignatureComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected EditorEx createEditor() {
  EditorEx editor = super.createEditor();
  final String fileName = getFileName();
  if (fileName != null) {
    editor.setHighlighter(EditorHighlighterFactory.getInstance().createEditorHighlighter(getProject(), fileName));
  }
  editor.getSettings().setWhitespacesShown(false);
  editor.setHorizontalScrollbarVisible(true);
  editor.setVerticalScrollbarVisible(true);
  return editor;
}
 
Example 7
Source File: QueryPanel.java    From nosql4idea with Apache License 2.0 4 votes vote down vote up
private void attachHighlighter(final EditorEx editor) {
    EditorColorsScheme scheme = editor.getColorsScheme();
    scheme.setColor(EditorColors.CARET_ROW_COLOR, null);
    editor.setHighlighter(createHighlighter(scheme));
}
 
Example 8
Source File: DiffUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void setEditorHighlighter(@Nullable Project project, @Nonnull EditorEx editor, @Nonnull DocumentContent content) {
  EditorHighlighter highlighter = createEditorHighlighter(project, content);
  if (highlighter != null) editor.setHighlighter(highlighter);
}
 
Example 9
Source File: EditorTextField.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected EditorEx createEditor() {
  LOG.assertTrue(myDocument != null);

  final EditorFactory factory = EditorFactory.getInstance();
  EditorEx editor = (EditorEx)(myIsViewer ? factory.createViewer(myDocument, myProject) : factory.createEditor(myDocument, myProject));

  final EditorSettings settings = editor.getSettings();
  settings.setAdditionalLinesCount(0);
  settings.setAdditionalColumnsCount(1);
  settings.setRightMarginShown(false);
  settings.setRightMargin(-1);
  settings.setFoldingOutlineShown(false);
  settings.setLineNumbersShown(false);
  settings.setLineMarkerAreaShown(false);
  settings.setIndentGuidesShown(false);
  settings.setVirtualSpace(false);
  settings.setWheelFontChangeEnabled(false);
  settings.setAdditionalPageAtBottom(false);
  editor.setHorizontalScrollbarVisible(false);
  editor.setVerticalScrollbarVisible(false);
  editor.setCaretEnabled(!myIsViewer);
  settings.setLineCursorWidth(1);

  JScrollPane scrollPane = editor.getScrollPane();
  scrollPane.setBorder(JBUI.Borders.empty());
  scrollPane.setViewportBorder(JBUI.Borders.empty());

  if (myProject != null) {
    PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(editor.getDocument());
    if (psiFile != null) {
      DaemonCodeAnalyzer.getInstance(myProject).setHighlightingEnabled(psiFile, !myIsViewer);
    }
  }

  if (myProject != null && myFileType != null) {
    editor.setHighlighter(EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, myFileType));
  }

  editor.getSettings().setCaretRowShown(false);

  editor.setOneLineMode(myOneLineMode);
  editor.getCaretModel().moveToOffset(myDocument.getTextLength());

  if (myIsViewer) {
    editor.getSelectionModel().removeSelection();
  }
  else if (myWholeTextSelected) {
    doSelectAll(editor);
    myWholeTextSelected = false;
  }

  editor.putUserData(SUPPLEMENTARY_KEY, myIsSupplementary);
  editor.getContentComponent().setFocusCycleRoot(false);
  editor.getContentComponent().addFocusListener(myProxyListeners);
  editor.getContentComponent().addMouseListener(myProxyListeners);

  editor.setPlaceholder(myHintText);

  initOneLineMode(editor);

  if (myIsRendererWithSelection) {
    ((DesktopEditorImpl)editor).setPaintSelection(true);
    editor.getColorsScheme().setColor(EditorColors.SELECTION_BACKGROUND_COLOR, myRendererBg);
    editor.getColorsScheme().setColor(EditorColors.SELECTION_FOREGROUND_COLOR, myRendererFg);
    editor.getSelectionModel().setSelection(0, myDocument.getTextLength());
    editor.setBackgroundColor(myRendererBg);
  }

  for (EditorSettingsProvider provider : mySettingsProviders) {
    provider.customizeSettings(editor);
  }

  return editor;
}
 
Example 10
Source File: CodeStyleAbstractPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void updatePreviewHighlighter(final EditorEx editor) {
  EditorColorsScheme scheme = editor.getColorsScheme();
  editor.getSettings().setCaretRowShown(false);
  editor.setHighlighter(createHighlighter(scheme));
}