Search in sources :

Example 1 with CaretAdapter

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

the class CaretModelWindow method addCaretListener.

@Override
public void addCaretListener(@NotNull final CaretListener listener) {
    CaretListener wrapper = new CaretAdapter() {

        @Override
        public void caretPositionChanged(CaretEvent e) {
            // injected document can be destroyed by now
            if (!myEditorWindow.getDocument().isValid())
                return;
            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);
}
Also used : CaretEvent(com.intellij.openapi.editor.event.CaretEvent) CaretListener(com.intellij.openapi.editor.event.CaretListener) CaretAdapter(com.intellij.openapi.editor.event.CaretAdapter)

Example 2 with CaretAdapter

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

the class FindUtil method processNotFound.

public static void processNotFound(final Editor editor, String stringToFind, FindModel model, Project project) {
    String message = FindBundle.message("find.search.string.not.found.message", stringToFind);
    short position = HintManager.UNDER;
    if (model.isGlobal()) {
        final FindModel newModel = model.clone();
        FindManager findManager = FindManager.getInstance(project);
        Document document = editor.getDocument();
        FindResult result = findManager.findString(document.getCharsSequence(), newModel.isForward() ? 0 : document.getTextLength(), model, getVirtualFile(editor));
        if (!result.isStringFound()) {
            result = null;
        }
        FindModel modelForNextSearch = findManager.getFindNextModel(editor);
        if (modelForNextSearch == null) {
            modelForNextSearch = findManager.getFindInFileModel();
        }
        if (result != null) {
            if (newModel.isForward()) {
                AnAction action = ActionManager.getInstance().getAction(modelForNextSearch.isForward() ? IdeActions.ACTION_FIND_NEXT : IdeActions.ACTION_FIND_PREVIOUS);
                String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText(action);
                if (!shortcutsText.isEmpty()) {
                    message = FindBundle.message("find.search.again.from.top.hotkey.message", message, shortcutsText);
                } else {
                    message = FindBundle.message("find.search.again.from.top.action.message", message);
                }
                editor.putUserData(KEY, Direction.DOWN);
            } else {
                AnAction action = ActionManager.getInstance().getAction(modelForNextSearch.isForward() ? IdeActions.ACTION_FIND_PREVIOUS : IdeActions.ACTION_FIND_NEXT);
                String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText(action);
                if (!shortcutsText.isEmpty()) {
                    message = FindBundle.message("find.search.again.from.bottom.hotkey.message", message, shortcutsText);
                } else {
                    message = FindBundle.message("find.search.again.from.bottom.action.message", message);
                }
                editor.putUserData(KEY, Direction.UP);
                position = HintManager.ABOVE;
            }
        }
        CaretListener listener = new CaretAdapter() {

            @Override
            public void caretPositionChanged(CaretEvent e) {
                editor.putUserData(KEY, null);
                editor.getCaretModel().removeCaretListener(this);
            }
        };
        editor.getCaretModel().addCaretListener(listener);
    }
    JComponent component = HintUtil.createInformationLabel(JDOMUtil.escapeText(message, false, false));
    final LightweightHint hint = new LightweightHint(component);
    HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, position, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0, false);
}
Also used : CaretEvent(com.intellij.openapi.editor.event.CaretEvent) CaretListener(com.intellij.openapi.editor.event.CaretListener) LightweightHint(com.intellij.ui.LightweightHint) CaretAdapter(com.intellij.openapi.editor.event.CaretAdapter)

Example 3 with CaretAdapter

use of com.intellij.openapi.editor.event.CaretAdapter 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

CaretAdapter (com.intellij.openapi.editor.event.CaretAdapter)3 CaretEvent (com.intellij.openapi.editor.event.CaretEvent)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 LightweightHint (com.intellij.ui.LightweightHint)1