protected TextEditorBasedStructureViewModel(Editor editor, PsiFile file) { myEditor = editor; myPsiFile = file; myEditorCaretListener = new CaretAdapter() { @Override public void caretPositionChanged(CaretEvent e) { if (e.getEditor().equals(myEditor)) { for (FileEditorPositionListener listener : myListeners) { listener.onCurrentElementChanged(); } } } }; }
public void addClickNavigator(final Editor view, final SyntaxHighlighter highlighter, final HighlightData[] data, final boolean isBackgroundImportant) { addMouseMotionListener(view, highlighter, data, isBackgroundImportant); CaretListener listener = new CaretAdapter() { @Override public void caretPositionChanged(CaretEvent e) { navigate(view, true, e.getNewPosition(), highlighter, data, isBackgroundImportant); } }; view.getCaretModel().addCaretListener(listener); }
public SimpleEditorPreview(final ColorAndFontOptions options, final ColorSettingsPage page, final boolean navigatable) { myOptions = options; myPage = page; String text = page.getDemoText(); HighlightsExtractor extractant2 = new HighlightsExtractor(page.getAdditionalHighlightingTagToDescriptorMap()); List<HighlightData> highlights = new ArrayList<HighlightData>(); String stripped = extractant2.extractHighlights(text, highlights); myHighlightData = highlights.toArray(new HighlightData[highlights.size()]); int selectedLine = -1; myEditor = (EditorEx)FontEditorPreview.createPreviewEditor(stripped, 10, 3, selectedLine, myOptions, false); FontEditorPreview.installTrafficLights(myEditor); myBlinkingAlarm = new Alarm().setActivationComponent(myEditor.getComponent()); if (navigatable) { addMouseMotionListener(myEditor, page.getHighlighter(), myHighlightData, false); CaretListener listener = new CaretAdapter() { @Override public void caretPositionChanged(CaretEvent e) { navigate(myEditor, true, e.getNewPosition(), page.getHighlighter(), myHighlightData, false); } }; myEditor.getCaretModel().addCaretListener(listener); } }
@Override public void addCaretListener(@NotNull final CaretListener listener) { CaretListener wrapper = new CaretAdapter() { @Override public void caretPositionChanged(CaretEvent e) { if (!myEditorWindow.getDocument().isValid()) return; // injected document can be destroyed by now CaretEvent event = new CaretEvent(myEditorWindow, createInjectedCaret(e.getCaret()), myEditorWindow.hostToInjected(e.getOldPosition()), myEditorWindow.hostToInjected(e.getNewPosition())); listener.caretPositionChanged(event); } }; myCaretListeners.registerWrapper(listener, wrapper); myDelegate.addCaretListener(wrapper); }