From 36cb45edc819f5a7282c060ba777c23d252d9957 Mon Sep 17 00:00:00 2001 From: Mihai Corlan Date: Thu, 4 Oct 2012 01:09:56 +0100 Subject: [PATCH 1/2] Delete current line/selection including end of line char --- src/editor/Editor.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 7dbcad5a374..6f0e6a07321 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -187,6 +187,25 @@ define(function (require, exports, module) { return handled; } + /** + * @private + * Deletes the current line if there is no selection or the lines for the selection + * (removing the end of line too) + * @param {!CodeMirror} instance CodeMirror instance + */ + function _deleteCurrentLines(instance) { + var from, to, sel; + sel = instance.getCursor(true); + from = {line: sel.line, ch: 0}; + sel = instance.getCursor(false); + to = {line: sel.line + 1, ch: 0}; + if (instance.lineCount() === to.line && from.line > 0) { + from.line -= 1; + from.ch = instance.getLine(from.line).length; + } + instance.replaceRange("", from, to); + } + /** * Checks if the user just typed a closing brace/bracket/paren, and considers automatically * back-indenting it if so. @@ -319,6 +338,9 @@ define(function (require, exports, module) { "Shift-Delete": "cut", "Ctrl-Insert": "copy", "Shift-Insert": "paste", + "Ctrl-Y": function (instance) { + _deleteCurrentLines(instance); + }, "'>'": function (cm) { cm.closeTag(cm, '>'); }, "'/'": function (cm) { cm.closeTag(cm, '/'); } }; From 97395a718d18178dd14e0380da315654086ed18a Mon Sep 17 00:00:00 2001 From: Mihai Corlan Date: Thu, 11 Oct 2012 13:30:05 +0300 Subject: [PATCH 2/2] Exposing the delete selected line(s) through menu Changed the code to be exposed in the Edit Menu; Shortcut chaged to Cmd-Shift-D (Ctrl-Shift-D); --- src/command/Commands.js | 1 + src/command/Menus.js | 1 + src/editor/Editor.js | 22 ---------------------- src/editor/EditorCommandHandlers.js | 25 +++++++++++++++++++++++++ src/nls/root/strings.js | 1 + 5 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/command/Commands.js b/src/command/Commands.js index 0a1b0ca195e..297acf0dd3c 100644 --- a/src/command/Commands.js +++ b/src/command/Commands.js @@ -62,6 +62,7 @@ define(function (require, exports, module) { exports.EDIT_INDENT = "edit.indent"; exports.EDIT_UNINDENT = "edit.unindent"; exports.EDIT_DUPLICATE = "edit.duplicate"; + exports.EDIT_DELETE_LINES = "edit.deletelines"; exports.EDIT_LINE_COMMENT = "edit.lineComment"; exports.EDIT_LINE_UP = "edit.lineUp"; exports.EDIT_LINE_DOWN = "edit.lineDown"; diff --git a/src/command/Menus.js b/src/command/Menus.js index 1ee43d89915..0a54757c13a 100644 --- a/src/command/Menus.js +++ b/src/command/Menus.js @@ -882,6 +882,7 @@ define(function (require, exports, module) { menu.addMenuItem(Commands.EDIT_INDENT, [{key: "Indent", displayKey: "Tab"}]); menu.addMenuItem(Commands.EDIT_UNINDENT, [{key: "Unindent", displayKey: "Shift-Tab"}]); menu.addMenuItem(Commands.EDIT_DUPLICATE, "Ctrl-D"); + menu.addMenuItem(Commands.EDIT_DELETE_LINES, "Ctrl-Shift-D"); menu.addMenuItem(Commands.EDIT_LINE_UP, [{key: "Ctrl-Shift-Up", displayKey: "Ctrl-Shift-\u2191", platform: "win"}, {key: "Cmd-Ctrl-Up", displayKey: "Cmd-Ctrl-\u2191", diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 448f4eb37a9..adda30fc4cb 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -198,25 +198,6 @@ define(function (require, exports, module) { return handled; } - /** - * @private - * Deletes the current line if there is no selection or the lines for the selection - * (removing the end of line too) - * @param {!CodeMirror} instance CodeMirror instance - */ - function _deleteCurrentLines(instance) { - var from, to, sel; - sel = instance.getCursor(true); - from = {line: sel.line, ch: 0}; - sel = instance.getCursor(false); - to = {line: sel.line + 1, ch: 0}; - if (instance.lineCount() === to.line && from.line > 0) { - from.line -= 1; - from.ch = instance.getLine(from.line).length; - } - instance.replaceRange("", from, to); - } - /** * Checks if the user just typed a closing brace/bracket/paren, and considers automatically * back-indenting it if so. @@ -342,9 +323,6 @@ define(function (require, exports, module) { "Shift-Delete": "cut", "Ctrl-Insert": "copy", "Shift-Insert": "paste", - "Ctrl-Y": function (instance) { - _deleteCurrentLines(instance); - }, "'>'": function (cm) { cm.closeTag(cm, '>'); }, "'/'": function (cm) { cm.closeTag(cm, '/'); } }; diff --git a/src/editor/EditorCommandHandlers.js b/src/editor/EditorCommandHandlers.js index 36cb95ddbd6..4fc9aed2023 100644 --- a/src/editor/EditorCommandHandlers.js +++ b/src/editor/EditorCommandHandlers.js @@ -159,6 +159,30 @@ define(function (require, exports, module) { var selectedText = doc.getRange(sel.start, sel.end) + delimiter; doc.replaceRange(selectedText, sel.start); } + + /** + * Deletes the current line if there is no selection or the lines for the selection + * (removing the end of line too) + */ + function deleteCurrentLines(editor) { + editor = editor || EditorManager.getFocusedEditor(); + if (!editor) { + return; + } + + var from, to, sel, doc; + + doc = editor._codeMirror; + sel = doc.getCursor(true); + from = {line: sel.line, ch: 0}; + sel = doc.getCursor(false); + to = {line: sel.line + 1, ch: 0}; + if (doc.lineCount() === to.line && from.line > 0) { + from.line -= 1; + from.ch = doc.getLine(from.line).length; + } + doc.replaceRange("", from, to); + } /** * Moves the selected text, or current line if no selection. The cursor/selection @@ -278,6 +302,7 @@ define(function (require, exports, module) { CommandManager.register(Strings.CMD_UNINDENT, Commands.EDIT_UNINDENT, unidentText); CommandManager.register(Strings.CMD_COMMENT, Commands.EDIT_LINE_COMMENT, lineComment); CommandManager.register(Strings.CMD_DUPLICATE, Commands.EDIT_DUPLICATE, duplicateText); + CommandManager.register(Strings.CMD_DELETE_LINES, Commands.EDIT_DELETE_LINES, deleteCurrentLines); CommandManager.register(Strings.CMD_LINE_UP, Commands.EDIT_LINE_UP, moveLineUp); CommandManager.register(Strings.CMD_LINE_DOWN, Commands.EDIT_LINE_DOWN, moveLineDown); CommandManager.register(Strings.CMD_USE_TAB_CHARS, Commands.TOGGLE_USE_TAB_CHARS, toggleUseTabChars) diff --git a/src/nls/root/strings.js b/src/nls/root/strings.js index 547aeb94f8e..54398e0c89e 100644 --- a/src/nls/root/strings.js +++ b/src/nls/root/strings.js @@ -177,6 +177,7 @@ define({ "CMD_INDENT" : "Indent", "CMD_UNINDENT" : "Unindent", "CMD_DUPLICATE" : "Duplicate", + "CMD_DELETE_LINES" : "Delete Selected Line(s)", "CMD_COMMENT" : "Comment/Uncomment Lines", "CMD_LINE_UP" : "Move Line(s) Up", "CMD_LINE_DOWN" : "Move Line(s) Down",