Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 97395a7

Browse files
committed
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);
1 parent aa97ba1 commit 97395a7

File tree

5 files changed

+28
-22
lines changed

5 files changed

+28
-22
lines changed

src/command/Commands.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ define(function (require, exports, module) {
6262
exports.EDIT_INDENT = "edit.indent";
6363
exports.EDIT_UNINDENT = "edit.unindent";
6464
exports.EDIT_DUPLICATE = "edit.duplicate";
65+
exports.EDIT_DELETE_LINES = "edit.deletelines";
6566
exports.EDIT_LINE_COMMENT = "edit.lineComment";
6667
exports.EDIT_LINE_UP = "edit.lineUp";
6768
exports.EDIT_LINE_DOWN = "edit.lineDown";

src/command/Menus.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,7 @@ define(function (require, exports, module) {
882882
menu.addMenuItem(Commands.EDIT_INDENT, [{key: "Indent", displayKey: "Tab"}]);
883883
menu.addMenuItem(Commands.EDIT_UNINDENT, [{key: "Unindent", displayKey: "Shift-Tab"}]);
884884
menu.addMenuItem(Commands.EDIT_DUPLICATE, "Ctrl-D");
885+
menu.addMenuItem(Commands.EDIT_DELETE_LINES, "Ctrl-Shift-D");
885886
menu.addMenuItem(Commands.EDIT_LINE_UP, [{key: "Ctrl-Shift-Up", displayKey: "Ctrl-Shift-\u2191",
886887
platform: "win"},
887888
{key: "Cmd-Ctrl-Up", displayKey: "Cmd-Ctrl-\u2191",

src/editor/Editor.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -198,25 +198,6 @@ define(function (require, exports, module) {
198198
return handled;
199199
}
200200

201-
/**
202-
* @private
203-
* Deletes the current line if there is no selection or the lines for the selection
204-
* (removing the end of line too)
205-
* @param {!CodeMirror} instance CodeMirror instance
206-
*/
207-
function _deleteCurrentLines(instance) {
208-
var from, to, sel;
209-
sel = instance.getCursor(true);
210-
from = {line: sel.line, ch: 0};
211-
sel = instance.getCursor(false);
212-
to = {line: sel.line + 1, ch: 0};
213-
if (instance.lineCount() === to.line && from.line > 0) {
214-
from.line -= 1;
215-
from.ch = instance.getLine(from.line).length;
216-
}
217-
instance.replaceRange("", from, to);
218-
}
219-
220201
/**
221202
* Checks if the user just typed a closing brace/bracket/paren, and considers automatically
222203
* back-indenting it if so.
@@ -342,9 +323,6 @@ define(function (require, exports, module) {
342323
"Shift-Delete": "cut",
343324
"Ctrl-Insert": "copy",
344325
"Shift-Insert": "paste",
345-
"Ctrl-Y": function (instance) {
346-
_deleteCurrentLines(instance);
347-
},
348326
"'>'": function (cm) { cm.closeTag(cm, '>'); },
349327
"'/'": function (cm) { cm.closeTag(cm, '/'); }
350328
};

src/editor/EditorCommandHandlers.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,30 @@ define(function (require, exports, module) {
159159
var selectedText = doc.getRange(sel.start, sel.end) + delimiter;
160160
doc.replaceRange(selectedText, sel.start);
161161
}
162+
163+
/**
164+
* Deletes the current line if there is no selection or the lines for the selection
165+
* (removing the end of line too)
166+
*/
167+
function deleteCurrentLines(editor) {
168+
editor = editor || EditorManager.getFocusedEditor();
169+
if (!editor) {
170+
return;
171+
}
172+
173+
var from, to, sel, doc;
174+
175+
doc = editor._codeMirror;
176+
sel = doc.getCursor(true);
177+
from = {line: sel.line, ch: 0};
178+
sel = doc.getCursor(false);
179+
to = {line: sel.line + 1, ch: 0};
180+
if (doc.lineCount() === to.line && from.line > 0) {
181+
from.line -= 1;
182+
from.ch = doc.getLine(from.line).length;
183+
}
184+
doc.replaceRange("", from, to);
185+
}
162186

163187
/**
164188
* Moves the selected text, or current line if no selection. The cursor/selection
@@ -278,6 +302,7 @@ define(function (require, exports, module) {
278302
CommandManager.register(Strings.CMD_UNINDENT, Commands.EDIT_UNINDENT, unidentText);
279303
CommandManager.register(Strings.CMD_COMMENT, Commands.EDIT_LINE_COMMENT, lineComment);
280304
CommandManager.register(Strings.CMD_DUPLICATE, Commands.EDIT_DUPLICATE, duplicateText);
305+
CommandManager.register(Strings.CMD_DELETE_LINES, Commands.EDIT_DELETE_LINES, deleteCurrentLines);
281306
CommandManager.register(Strings.CMD_LINE_UP, Commands.EDIT_LINE_UP, moveLineUp);
282307
CommandManager.register(Strings.CMD_LINE_DOWN, Commands.EDIT_LINE_DOWN, moveLineDown);
283308
CommandManager.register(Strings.CMD_USE_TAB_CHARS, Commands.TOGGLE_USE_TAB_CHARS, toggleUseTabChars)

src/nls/root/strings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ define({
177177
"CMD_INDENT" : "Indent",
178178
"CMD_UNINDENT" : "Unindent",
179179
"CMD_DUPLICATE" : "Duplicate",
180+
"CMD_DELETE_LINES" : "Delete Selected Line(s)",
180181
"CMD_COMMENT" : "Comment/Uncomment Lines",
181182
"CMD_LINE_UP" : "Move Line(s) Up",
182183
"CMD_LINE_DOWN" : "Move Line(s) Down",

0 commit comments

Comments
 (0)