Search in sources :

Example 1 with CaretListener

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

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

Aggregations

CaretAdapter (com.intellij.openapi.editor.event.CaretAdapter)2 CaretEvent (com.intellij.openapi.editor.event.CaretEvent)2 CaretListener (com.intellij.openapi.editor.event.CaretListener)2 LightweightHint (com.intellij.ui.LightweightHint)1