Example usage for com.intellij.openapi.actionSystem IdeActions ACTION_EDITOR_MOVE_LINE_END

List of usage examples for com.intellij.openapi.actionSystem IdeActions ACTION_EDITOR_MOVE_LINE_END

Introduction

In this page you can find the example usage for com.intellij.openapi.actionSystem IdeActions ACTION_EDITOR_MOVE_LINE_END.

Prototype

String ACTION_EDITOR_MOVE_LINE_END

To view the source code for com.intellij.openapi.actionSystem IdeActions ACTION_EDITOR_MOVE_LINE_END.

Click Source Link

Usage

From source file:com.hp.alm.ali.idea.ui.editor.field.HTMLAreaField.java

License:Apache License

public static void installNavigationShortCuts(final JTextPane desc) {
    Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    new AnAction() {
        public void actionPerformed(AnActionEvent e) {
            // default action moves to the end of the document - override
            desc.getActionMap().get(DefaultEditorKit.endLineAction).actionPerformed(null);
        }// w w  w  .  j  av  a 2s  .  c  o  m
    }.registerCustomShortcutSet(
            new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_EDITOR_MOVE_LINE_END)), desc);
    new AnAction() {
        public void actionPerformed(AnActionEvent e) {
            // default action moves to the beginning of the document - override
            desc.getActionMap().get(DefaultEditorKit.beginLineAction).actionPerformed(null);
        }
    }.registerCustomShortcutSet(
            new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_EDITOR_MOVE_LINE_START)), desc);
    new AnAction() {
        public void actionPerformed(AnActionEvent e) {
            // default action moves to the end of the document - override
            desc.getActionMap().get(DefaultEditorKit.selectionEndLineAction).actionPerformed(null);
        }
    }.registerCustomShortcutSet(
            new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_END, InputEvent.SHIFT_MASK)), desc);
    new AnAction() {
        public void actionPerformed(AnActionEvent e) {
            // default action moves to the beginning of the document - override
            desc.getActionMap().get(DefaultEditorKit.selectionBeginLineAction).actionPerformed(null);
        }
    }.registerCustomShortcutSet(
            new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, InputEvent.SHIFT_MASK)), desc);
    new AnAction() {
        public void actionPerformed(AnActionEvent e) {
            // when editing html insert hard break
            new InsertHardBreakAction().actionPerformed(null);
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)), desc);
}

From source file:com.intellij.codeInsight.editorActions.smartEnter.LeaveCodeBlockEnterProcessor.java

License:Apache License

@Override
public boolean doEnter(Editor editor, PsiElement psiElement, boolean isModified) {
    PsiElement parent = psiElement.getParent();
    if (!(parent instanceof PsiCodeBlock)) {
        return false;
    }/*ww w.ja v  a2s. c  o  m*/

    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;
}

From source file:com.intellij.codeInsight.editorActions.smartEnter.PlainEnterProcessor.java

License:Apache License

/**
 * There is a possible case that target code block already starts with the empty line:
 * <pre>/*from  www  .j a v  a2s .  c  om*/
 *   void test(int i) {
 *     if (i > 1[caret]) {
 *       
 *     }
 *   }
 * </pre>
 * We want just move caret to correct position at that empty line without creating additional empty line then.
 *  
 * @param editor      target editor
 * @param codeBlock   target code block to which new empty line is going to be inserted
 * @param element     target element under caret
 * @return            <code>true</code> if it was found out that the given code block starts with the empty line and caret
 *                    is pointed to correct position there, i.e. no additional processing is required;
 *                    <code>false</code> otherwise
 */
private static boolean processExistingBlankLine(@NotNull Editor editor, @Nullable PsiCodeBlock codeBlock,
        @Nullable PsiElement element) {
    PsiWhiteSpace whiteSpace = null;
    if (codeBlock == null) {
        if (element != null) {
            final PsiElement next = PsiTreeUtil.nextLeaf(element);
            if (next instanceof PsiWhiteSpace) {
                whiteSpace = (PsiWhiteSpace) next;
            }
        }
    } else {
        whiteSpace = PsiTreeUtil.findChildOfType(codeBlock, PsiWhiteSpace.class);
        if (whiteSpace == null) {
            return false;
        }

        PsiElement lbraceCandidate = whiteSpace.getPrevSibling();
        if (lbraceCandidate == null) {
            return false;
        }

        ASTNode node = lbraceCandidate.getNode();
        if (node == null || node.getElementType() != JavaTokenType.LBRACE) {
            return false;
        }
    }

    if (whiteSpace == null) {
        return false;
    }

    final TextRange textRange = whiteSpace.getTextRange();
    final Document document = editor.getDocument();
    final CharSequence whiteSpaceText = document.getCharsSequence().subSequence(textRange.getStartOffset(),
            textRange.getEndOffset());
    if (StringUtil.countNewLines(whiteSpaceText) < 2) {
        return false;
    }

    int i = CharArrayUtil.shiftForward(whiteSpaceText, 0, " \t");
    if (i >= whiteSpaceText.length() - 1) {
        assert false : String.format("code block: %s, white space: %s",
                codeBlock == null ? "undefined" : codeBlock.getTextRange(), whiteSpace.getTextRange());
        return false;
    }

    editor.getCaretModel().moveToOffset(i + 1 + textRange.getStartOffset());
    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) {
        i = CharArrayUtil.shiftForwardUntil(whiteSpaceText, i, "\n");
        if (i >= whiteSpaceText.length()) {
            i = whiteSpaceText.length();
        }
        editor.getCaretModel().moveToOffset(i + textRange.getStartOffset());
    } else {
        actionHandler.execute(editor, dataContext);
    }
    return true;
}

From source file:com.intellij.testFramework.LightPlatformCodeInsightTestCase.java

License:Apache License

protected static void end() {
    executeAction(IdeActions.ACTION_EDITOR_MOVE_LINE_END);
}