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

Adding support for delete entire line/lines #1763

Merged
merged 3 commits into from
Oct 12, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/command/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions src/command/Menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 25 additions & 0 deletions src/editor/EditorCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down