Search in sources :

Example 1 with EditorActionManager

use of com.intellij.openapi.editor.actionSystem.EditorActionManager in project intellij-community by JetBrains.

the class IncrementalSearchHandler method invoke.

public void invoke(Project project, final Editor editor) {
    if (!ourActionsRegistered) {
        EditorActionManager actionManager = EditorActionManager.getInstance();
        TypedAction typedAction = actionManager.getTypedAction();
        typedAction.setupRawHandler(new MyTypedHandler(typedAction.getRawHandler()));
        actionManager.setActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE, new BackSpaceHandler(actionManager.getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE)));
        actionManager.setActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_UP, new UpHandler(actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_UP)));
        actionManager.setActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN, new DownHandler(actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN)));
        ourActionsRegistered = true;
    }
    FeatureUsageTracker.getInstance().triggerFeatureUsed("editing.incremental.search");
    String selection = editor.getSelectionModel().getSelectedText();
    JLabel label2 = new MyLabel(selection == null ? "" : selection);
    PerEditorSearchData data = editor.getUserData(SEARCH_DATA_IN_EDITOR_VIEW_KEY);
    if (data == null) {
        data = new PerEditorSearchData();
    } else {
        if (data.hint != null) {
            if (data.lastSearch != null) {
                PerHintSearchData hintData = data.hint.getUserData(SEARCH_DATA_IN_HINT_KEY);
                //The user has not started typing
                if ("".equals(hintData.label.getText())) {
                    label2 = new MyLabel(data.lastSearch);
                }
            }
            data.hint.hide();
        }
    }
    JLabel label1 = new MyLabel(" " + CodeInsightBundle.message("incremental.search.tooltip.prefix"));
    label1.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));
    JPanel panel = new MyPanel(label1);
    panel.add(label1, BorderLayout.WEST);
    panel.add(label2, BorderLayout.CENTER);
    panel.setBorder(BorderFactory.createLineBorder(Color.black));
    final DocumentListener[] documentListener = new DocumentListener[1];
    final CaretListener[] caretListener = new CaretListener[1];
    final Document document = editor.getDocument();
    final LightweightHint hint = new LightweightHint(panel) {

        @Override
        public void hide() {
            PerHintSearchData data = getUserData(SEARCH_DATA_IN_HINT_KEY);
            LOG.assertTrue(data != null);
            String prefix = data.label.getText();
            super.hide();
            if (data.segmentHighlighter != null) {
                data.segmentHighlighter.dispose();
            }
            PerEditorSearchData editorData = editor.getUserData(SEARCH_DATA_IN_EDITOR_VIEW_KEY);
            editorData.hint = null;
            editorData.lastSearch = prefix;
            if (documentListener[0] != null) {
                document.removeDocumentListener(documentListener[0]);
                documentListener[0] = null;
            }
            if (caretListener[0] != null) {
                CaretListener listener = caretListener[0];
                editor.getCaretModel().removeCaretListener(listener);
            }
        }
    };
    documentListener[0] = new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            if (!hint.isVisible())
                return;
            hint.hide();
        }
    };
    document.addDocumentListener(documentListener[0]);
    caretListener[0] = new CaretAdapter() {

        @Override
        public void caretPositionChanged(CaretEvent e) {
            PerHintSearchData data = hint.getUserData(SEARCH_DATA_IN_HINT_KEY);
            if (data != null && data.ignoreCaretMove)
                return;
            if (!hint.isVisible())
                return;
            hint.hide();
        }
    };
    CaretListener listener = caretListener[0];
    editor.getCaretModel().addCaretListener(listener);
    final JComponent component = editor.getComponent();
    int x = SwingUtilities.convertPoint(component, 0, 0, component).x;
    int y = -hint.getComponent().getPreferredSize().height;
    Point p = SwingUtilities.convertPoint(component, x, y, component.getRootPane().getLayeredPane());
    HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, p, HintManagerImpl.HIDE_BY_ESCAPE | HintManagerImpl.HIDE_BY_TEXT_CHANGE, 0, false, new HintHint(editor, p).setAwtTooltip(false));
    PerHintSearchData hintData = new PerHintSearchData(project, label2);
    hintData.searchStart = editor.getCaretModel().getOffset();
    hint.putUserData(SEARCH_DATA_IN_HINT_KEY, hintData);
    data.hint = hint;
    editor.putUserData(SEARCH_DATA_IN_EDITOR_VIEW_KEY, data);
    if (hintData.label.getText().length() > 0) {
        updatePosition(editor, hintData, true, false);
    }
}
Also used : Document(com.intellij.openapi.editor.Document) LightweightHint(com.intellij.ui.LightweightHint) TypedAction(com.intellij.openapi.editor.actionSystem.TypedAction) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint) EditorActionManager(com.intellij.openapi.editor.actionSystem.EditorActionManager) HintHint(com.intellij.ui.HintHint)

Example 2 with EditorActionManager

use of com.intellij.openapi.editor.actionSystem.EditorActionManager in project intellij-community by JetBrains.

the class LeaveCodeBlockEnterProcessor method doEnter.

@Override
public boolean doEnter(Editor editor, PsiElement psiElement, boolean isModified) {
    PsiElement parent = psiElement.getParent();
    if (!(parent instanceof PsiCodeBlock)) {
        return false;
    }
    final ASTNode node = psiElement.getNode();
    if (node != null && CONTROL_FLOW_ELEMENT_TYPES.contains(node.getElementType())) {
        return false;
    }
    boolean leaveCodeBlock = isControlFlowBreak(psiElement);
    if (!leaveCodeBlock) {
        return false;
    }
    final int offset = parent.getTextRange().getEndOffset();
    // Check if there is empty line after the code block. Just move caret there in the case of the positive answer.
    final CharSequence text = editor.getDocument().getCharsSequence();
    if (offset < text.length() - 1) {
        final int i = CharArrayUtil.shiftForward(text, offset + 1, " \t");
        if (i < text.length() && text.charAt(i) == '\n') {
            editor.getCaretModel().moveToOffset(offset + 1);
            EditorActionManager actionManager = EditorActionManager.getInstance();
            EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_LINE_END);
            final DataContext dataContext = DataManager.getInstance().getDataContext(editor.getComponent());
            if (dataContext != null) {
                actionHandler.execute(editor, dataContext);
                return true;
            }
        }
    }
    editor.getCaretModel().moveToOffset(offset);
    return false;
}
Also used : EditorActionManager(com.intellij.openapi.editor.actionSystem.EditorActionManager) PsiCodeBlock(com.intellij.psi.PsiCodeBlock) DataContext(com.intellij.openapi.actionSystem.DataContext) ASTNode(com.intellij.lang.ASTNode) EditorActionHandler(com.intellij.openapi.editor.actionSystem.EditorActionHandler) PsiElement(com.intellij.psi.PsiElement)

Example 3 with EditorActionManager

use of com.intellij.openapi.editor.actionSystem.EditorActionManager in project intellij-community by JetBrains.

the class GenerateJavadocTest method performAction.

private void performAction() {
    EditorActionManager actionManager = EditorActionManager.getInstance();
    EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_ENTER);
    actionHandler.execute(myEditor, DataManager.getInstance().getDataContext());
}
Also used : EditorActionManager(com.intellij.openapi.editor.actionSystem.EditorActionManager) EditorActionHandler(com.intellij.openapi.editor.actionSystem.EditorActionHandler)

Example 4 with EditorActionManager

use of com.intellij.openapi.editor.actionSystem.EditorActionManager in project intellij-community by JetBrains.

the class ConsoleViewImplTest method testTypingAfterMultipleCR.

public void testTypingAfterMultipleCR() throws Exception {
    final EditorActionManager actionManager = EditorActionManager.getInstance();
    final TypedAction typedAction = actionManager.getTypedAction();
    final TestDataProvider dataContext = new TestDataProvider(getProject());
    final ConsoleViewImpl console = myConsole;
    final Editor editor = console.getEditor();
    console.print("System output\n", ConsoleViewContentType.SYSTEM_OUTPUT);
    console.print("\r\r\r\r\r\r\r", ConsoleViewContentType.NORMAL_OUTPUT);
    console.flushDeferredText();
    typedAction.actionPerformed(editor, '1', dataContext);
    typedAction.actionPerformed(editor, '2', dataContext);
    assertEquals("System output\n12", editor.getDocument().getText());
}
Also used : EditorActionManager(com.intellij.openapi.editor.actionSystem.EditorActionManager) TypedAction(com.intellij.openapi.editor.actionSystem.TypedAction) Editor(com.intellij.openapi.editor.Editor)

Example 5 with EditorActionManager

use of com.intellij.openapi.editor.actionSystem.EditorActionManager in project intellij-community by JetBrains.

the class LightPlatformCodeInsightTestCase method type.

public static void type(char c, @NotNull Editor editor, Project project) {
    if (c == '\n') {
        executeAction(IdeActions.ACTION_EDITOR_ENTER, editor, project);
    } else {
        EditorActionManager actionManager = EditorActionManager.getInstance();
        final DataContext dataContext = DataManager.getInstance().getDataContext();
        TypedAction action = actionManager.getTypedAction();
        action.actionPerformed(editor, c, dataContext);
    }
}
Also used : EditorActionManager(com.intellij.openapi.editor.actionSystem.EditorActionManager) DataContext(com.intellij.openapi.actionSystem.DataContext) TypedAction(com.intellij.openapi.editor.actionSystem.TypedAction)

Aggregations

EditorActionManager (com.intellij.openapi.editor.actionSystem.EditorActionManager)11 EditorActionHandler (com.intellij.openapi.editor.actionSystem.EditorActionHandler)7 TypedAction (com.intellij.openapi.editor.actionSystem.TypedAction)4 DataContext (com.intellij.openapi.actionSystem.DataContext)3 ASTNode (com.intellij.lang.ASTNode)2 Document (com.intellij.openapi.editor.Document)2 Editor (com.intellij.openapi.editor.Editor)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiCodeBlock (com.intellij.psi.PsiCodeBlock)1 PsiElement (com.intellij.psi.PsiElement)1 HintHint (com.intellij.ui.HintHint)1 LightweightHint (com.intellij.ui.LightweightHint)1