Search in sources :

Example 6 with CaretEvent

use of com.intellij.openapi.editor.event.CaretEvent in project intellij-community by JetBrains.

the class EmmetPreviewUtil method addEmmetPreviewListeners.

public static void addEmmetPreviewListeners(@NotNull final Editor editor, @NotNull final PsiFile file, final boolean expandPrimitiveAbbreviations) {
    editor.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(@NotNull DocumentEvent e) {
            EmmetPreviewHint existingHint = EmmetPreviewHint.getExistingHint(editor);
            if (existingHint != null) {
                existingHint.updateText(new TemplateTextProducer(editor, file, expandPrimitiveAbbreviations));
            } else {
                e.getDocument().removeDocumentListener(this);
            }
        }
    });
    editor.getCaretModel().addCaretListener(new CaretAdapter() {

        @Override
        public void caretPositionChanged(@NotNull CaretEvent e) {
            EmmetPreviewHint existingHint = EmmetPreviewHint.getExistingHint(e.getEditor());
            if (existingHint != null) {
                existingHint.updateText(new TemplateTextProducer(editor, file, expandPrimitiveAbbreviations));
            } else {
                e.getEditor().getCaretModel().removeCaretListener(this);
            }
        }
    });
}
Also used : CaretEvent(com.intellij.openapi.editor.event.CaretEvent) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) CaretAdapter(com.intellij.openapi.editor.event.CaretAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Aggregations

CaretEvent (com.intellij.openapi.editor.event.CaretEvent)6 CaretAdapter (com.intellij.openapi.editor.event.CaretAdapter)3 CaretListener (com.intellij.openapi.editor.event.CaretListener)2 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 DocumentEx (com.intellij.openapi.editor.ex.DocumentEx)1 LightweightHint (com.intellij.ui.LightweightHint)1