IDEA-69728 "Start New Line" shortcut for starting a new line above the current line
authorDenis Zhdanov <Denis.Zhdanov@jetbrains.com>
Thu, 19 May 2011 07:13:20 +0000 (11:13 +0400)
committerDenis Zhdanov <Denis.Zhdanov@jetbrains.com>
Thu, 19 May 2011 07:13:20 +0000 (11:13 +0400)
platform/platform-impl/src/com/intellij/openapi/editor/actions/StartNewLineAction.java
platform/platform-impl/src/com/intellij/openapi/editor/actions/StartNewLineBeforeAction.java [new file with mode: 0644]
platform/platform-resources-en/src/messages/ActionsBundle.properties
platform/platform-resources/src/idea/Keymap_Default.xml
platform/platform-resources/src/idea/PlatformActions.xml

index 1c05cd796fe68481e549006c59fa66e757380bce..968da69e1df219db7688096ae6c1c0d027440373 100644 (file)
@@ -48,7 +48,7 @@ public class StartNewLineAction extends EditorAction {
       getEnterHandler().execute(editor, dataContext);
     }
 
-    private EditorActionHandler getEnterHandler() {
+    private static EditorActionHandler getEnterHandler() {
       return EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER);
     }
   }
diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/StartNewLineBeforeAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/StartNewLineBeforeAction.java
new file mode 100644 (file)
index 0000000..81e1289
--- /dev/null
@@ -0,0 +1,43 @@
+package com.intellij.openapi.editor.actions;
+
+import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.actionSystem.IdeActions;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.editor.LogicalPosition;
+import com.intellij.openapi.editor.actionSystem.EditorAction;
+import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
+import com.intellij.openapi.editor.actionSystem.EditorActionManager;
+import com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author Denis Zhdanov
+ * @since 5/19/11 10:42 AM
+ */
+public class StartNewLineBeforeAction extends EditorAction {
+
+  public StartNewLineBeforeAction() {
+    super(new Handler());
+  }
+
+  private static class Handler extends EditorWriteActionHandler {
+    public boolean isEnabled(Editor editor, DataContext dataContext) {
+      return getHandler(IdeActions.ACTION_EDITOR_ENTER).isEnabled(editor, dataContext);
+    }
+
+    public void executeWriteAction(Editor editor, DataContext dataContext) {
+      editor.getSelectionModel().removeSelection();
+      LogicalPosition caretPosition = editor.getCaretModel().getLogicalPosition();
+      final int line = caretPosition.line;
+      int lineStartOffset = editor.getDocument().getLineStartOffset(line);
+      editor.getCaretModel().moveToOffset(lineStartOffset);
+      getHandler(IdeActions.ACTION_EDITOR_ENTER).execute(editor, dataContext);
+      editor.getCaretModel().moveToOffset(editor.getDocument().getLineStartOffset(line));
+      getHandler(IdeActions.ACTION_EDITOR_MOVE_LINE_END).execute(editor, dataContext);
+    }
+
+    private static EditorActionHandler getHandler(@NotNull String actionId) {
+      return EditorActionManager.getInstance().getActionHandler(actionId);
+    }
+  }
+}
index f372113e7992394a1e431fd076d30b9d6df4e4df..aee46b03d210675ed36dc2ba662dc3778a8759e6 100644 (file)
@@ -143,6 +143,7 @@ action.EditorJoinLines.text=Join Lines
 action.EditorSelectLine.text=Select Line at Caret
 action.EditorSplitLine.text=Split Line
 action.EditorStartNewLine.text=Start New Line
+action.EditorStartNewLineBefore.text=Start New Line Before Current
 action.EditorCompleteStatement.text=Complete Current Statement
 action.ExpandAll.text=Expand All
 action.CollapseAll.text=Collapse All
index 25b7bc6ecd36a9d64fde7356319ae77fd642ee60..c56878c6df3ee44fa712262adf0b47f9a310f990 100644 (file)
   <action id="EditorStartNewLine">
     <keyboard-shortcut first-keystroke="shift ENTER"/>
   </action>
+  <action id="EditorStartNewLineBefore">
+    <keyboard-shortcut first-keystroke="control alt ENTER"/>
+  </action>
   <action id="EditorLeft">
     <keyboard-shortcut first-keystroke="LEFT"/>
   </action>
index 72e26190e94ca11b0f0ef65ee691558f4691fdd8..270dce1ef8bc5b3762de42b5276c4f6abcae3a1f 100644 (file)
@@ -97,6 +97,7 @@
       <action id="EditorSelectLine" class="com.intellij.openapi.editor.actions.SelectLineAction"/>
       <action id="EditorSplitLine" class="com.intellij.openapi.editor.actions.SplitLineAction"/>
       <action id="EditorStartNewLine" class="com.intellij.openapi.editor.actions.StartNewLineAction"/>
+      <action id="EditorStartNewLineBefore" class="com.intellij.openapi.editor.actions.StartNewLineBeforeAction"/>
     </group>
 
     <action id="ExpandAll" class="com.intellij.ide.actions.ExpandAllAction" icon="/actions/expandall.png"/>