use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class SimpleDiffChange method createOperation.
//
// Helpers
//
@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);
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class DocumentMarkupModelTest method testInfoTestAttributes.
public void testInfoTestAttributes() throws Exception {
LanguageExtensionPoint<Annotator> extension = new LanguageExtensionPoint<>();
extension.language = "TEXT";
extension.implementationClass = TestAnnotator.class.getName();
PlatformTestUtil.registerExtension(ExtensionPointName.create(LanguageAnnotators.EP_NAME), extension, myFixture.getTestRootDisposable());
myFixture.configureByText(PlainTextFileType.INSTANCE, "foo");
EditorColorsScheme scheme = new EditorColorsSchemeImpl(new DefaultColorsScheme()) {
{
initFonts();
}
};
scheme.setAttributes(HighlighterColors.TEXT, new TextAttributes(Color.black, Color.white, null, null, Font.PLAIN));
((EditorEx) myFixture.getEditor()).setColorsScheme(scheme);
myFixture.doHighlighting();
MarkupModel model = DocumentMarkupModel.forDocument(myFixture.getEditor().getDocument(), getProject(), false);
RangeHighlighter[] highlighters = model.getAllHighlighters();
assertThat(highlighters).hasSize(1);
TextAttributes attributes = highlighters[0].getTextAttributes();
assertThat(attributes).isNotNull();
assertThat(attributes.getBackgroundColor()).isNull();
assertThat(attributes.getForegroundColor()).isNull();
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class ConsoleViewUtil method setupConsoleEditor.
@NotNull
public static EditorEx setupConsoleEditor(Project project, final boolean foldingOutlineShown, final boolean lineMarkerAreaShown) {
EditorFactory editorFactory = EditorFactory.getInstance();
Document document = ((EditorFactoryImpl) editorFactory).createDocument(true);
UndoUtil.disableUndoFor(document);
EditorEx editor = (EditorEx) editorFactory.createViewer(document, project);
setupConsoleEditor(editor, foldingOutlineShown, lineMarkerAreaShown);
return editor;
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class EventLogToolWindowFactory method createContent.
static void createContent(Project project, ToolWindow toolWindow, EventLogConsole console, String title) {
// update default Event Log tab title
ContentManager contentManager = toolWindow.getContentManager();
Content generalContent = contentManager.getContent(0);
if (generalContent != null && contentManager.getContentCount() == 1) {
generalContent.setDisplayName("General");
}
final Editor editor = console.getConsoleEditor();
JPanel editorPanel = new JPanel(new AbstractLayoutManager() {
private int getOffset() {
return JBUI.scale(4);
}
@Override
public Dimension preferredLayoutSize(Container parent) {
Dimension size = parent.getComponent(0).getPreferredSize();
return new Dimension(size.width + getOffset(), size.height);
}
@Override
public void layoutContainer(Container parent) {
int offset = getOffset();
parent.getComponent(0).setBounds(offset, 0, parent.getWidth() - offset, parent.getHeight());
}
}) {
@Override
public Color getBackground() {
return ((EditorEx) editor).getBackgroundColor();
}
};
editorPanel.add(editor.getComponent());
SimpleToolWindowPanel panel = new SimpleToolWindowPanel(false, true) {
@Override
public Object getData(@NonNls String dataId) {
return PlatformDataKeys.HELP_ID.is(dataId) ? EventLog.HELP_ID : super.getData(dataId);
}
};
panel.setContent(editorPanel);
panel.addAncestorListener(new LogShownTracker(project));
ActionToolbar toolbar = createToolbar(project, editor, console);
toolbar.setTargetComponent(editor.getContentComponent());
panel.setToolbar(toolbar.getComponent());
Content content = ContentFactory.SERVICE.getInstance().createContent(panel, title, false);
contentManager.addContent(content);
contentManager.setSelectedContent(content);
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class ToggleColumnModeAction method setSelected.
@Override
public void setSelected(AnActionEvent e, boolean state) {
final EditorEx editor = getEditor(e);
final SelectionModel selectionModel = editor.getSelectionModel();
final CaretModel caretModel = editor.getCaretModel();
if (state) {
caretModel.removeSecondaryCarets();
boolean hasSelection = selectionModel.hasSelection();
int selStart = selectionModel.getSelectionStart();
int selEnd = selectionModel.getSelectionEnd();
LogicalPosition blockStart, blockEnd;
if (caretModel.supportsMultipleCarets()) {
LogicalPosition logicalSelStart = editor.offsetToLogicalPosition(selStart);
LogicalPosition logicalSelEnd = editor.offsetToLogicalPosition(selEnd);
int caretOffset = caretModel.getOffset();
blockStart = selStart == caretOffset ? logicalSelEnd : logicalSelStart;
blockEnd = selStart == caretOffset ? logicalSelStart : logicalSelEnd;
} else {
blockStart = selStart == caretModel.getOffset() ? caretModel.getLogicalPosition() : editor.offsetToLogicalPosition(selStart);
blockEnd = selEnd == caretModel.getOffset() ? caretModel.getLogicalPosition() : editor.offsetToLogicalPosition(selEnd);
}
editor.setColumnMode(true);
if (hasSelection) {
selectionModel.setBlockSelection(blockStart, blockEnd);
} else {
selectionModel.removeSelection();
}
} else {
boolean hasSelection = false;
int selStart = 0;
int selEnd = 0;
if (caretModel.supportsMultipleCarets()) {
hasSelection = true;
List<Caret> allCarets = caretModel.getAllCarets();
Caret fromCaret = allCarets.get(0);
Caret toCaret = allCarets.get(allCarets.size() - 1);
if (fromCaret == caretModel.getPrimaryCaret()) {
Caret tmp = fromCaret;
fromCaret = toCaret;
toCaret = tmp;
}
selStart = fromCaret.getLeadSelectionOffset();
selEnd = toCaret.getSelectionStart() == toCaret.getLeadSelectionOffset() ? toCaret.getSelectionEnd() : toCaret.getSelectionStart();
}
editor.setColumnMode(false);
caretModel.removeSecondaryCarets();
if (hasSelection) {
selectionModel.setSelection(selStart, selEnd);
} else {
selectionModel.removeSelection();
}
}
}
Aggregations