From 2ccd4cee609d5f9cb30bd7acdab2c96929a8f066 Mon Sep 17 00:00:00 2001 From: Dimitar Spiroski Date: Sun, 26 Aug 2012 17:13:34 +0200 Subject: [PATCH 1/5] Ctrl+L selects line + menu item for select line --- src/command/Commands.js | 1 + src/command/Menus.js | 1 + src/editor/Editor.js | 11 ++++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/command/Commands.js b/src/command/Commands.js index 6cb737ef3f6..5a2903721b3 100644 --- a/src/command/Commands.js +++ b/src/command/Commands.js @@ -52,6 +52,7 @@ define(function (require, exports, module) { exports.EDIT_COPY = "edit.copy"; exports.EDIT_PASTE = "edit.paste"; exports.EDIT_SELECT_ALL = "edit.selectAll"; + exports.EDIT_SELECT_LINE = "edit.selectLine"; exports.EDIT_FIND = "edit.find"; exports.EDIT_FIND_IN_FILES = "edit.findInFiles"; exports.EDIT_FIND_NEXT = "edit.findNext"; diff --git a/src/command/Menus.js b/src/command/Menus.js index 7779f7cee4c..2c69765c1a9 100644 --- a/src/command/Menus.js +++ b/src/command/Menus.js @@ -862,6 +862,7 @@ define(function (require, exports, module) { */ menu = addMenu(Strings.EDIT_MENU, AppMenuBar.EDIT_MENU); menu.addMenuItem(Commands.EDIT_SELECT_ALL, "Ctrl-A"); + menu.addMenuItem(Commands.EDIT_SELECT_LINE, "Ctrl-L"); menu.addMenuDivider(); menu.addMenuItem(Commands.EDIT_FIND, "Ctrl-F"); menu.addMenuItem(Commands.EDIT_FIND_IN_FILES, "Ctrl-Shift-F"); diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 0fb461e5699..4ff8aafb169 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -225,6 +225,15 @@ define(function (require, exports, module) { } } + function _handleSelectLine() { + var editor = EditorManager.getFocusedEditor(); + if (editor) { + var cursor = editor.getCursorPos(), + from = {line: cursor.line, ch: 0}, + to = {line: cursor.line, ch: editor.document.getLine(cursor.line).length}; + editor.setSelection(from, to); + } + } /** * List of all current (non-destroy()ed) Editor instances. Needed when changing global preferences @@ -1056,7 +1065,7 @@ define(function (require, exports, module) { // Global commands that affect the currently focused Editor instance, wherever it may be CommandManager.register(Strings.CMD_SELECT_ALL, Commands.EDIT_SELECT_ALL, _handleSelectAll); - + CommandManager.register("Select Line", Commands.EDIT_SELECT_LINE, _handleSelectLine); // Define public API exports.Editor = Editor; }); From 97cf253a79c26bea3973f3daf4a79e0835e3cde1 Mon Sep 17 00:00:00 2001 From: Dimitar Spiroski Date: Tue, 28 Aug 2012 00:53:36 +0200 Subject: [PATCH 2/5] sugestions implemented --- src/command/Menus.js | 2 +- src/editor/Editor.js | 13 +------------ src/editor/EditorCommandHandlers.js | 11 +++++++++++ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/command/Menus.js b/src/command/Menus.js index 2c69765c1a9..31722030077 100644 --- a/src/command/Menus.js +++ b/src/command/Menus.js @@ -862,7 +862,7 @@ define(function (require, exports, module) { */ menu = addMenu(Strings.EDIT_MENU, AppMenuBar.EDIT_MENU); menu.addMenuItem(Commands.EDIT_SELECT_ALL, "Ctrl-A"); - menu.addMenuItem(Commands.EDIT_SELECT_LINE, "Ctrl-L"); + menu.addMenuItem(Commands.EDIT_SELECT_LINE, "Ctrl-L"); menu.addMenuDivider(); menu.addMenuItem(Commands.EDIT_FIND, "Ctrl-F"); menu.addMenuItem(Commands.EDIT_FIND_IN_FILES, "Ctrl-Shift-F"); diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 4ff8aafb169..9be71d1a886 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -224,17 +224,7 @@ define(function (require, exports, module) { editor._selectAllVisible(); } } - - function _handleSelectLine() { - var editor = EditorManager.getFocusedEditor(); - if (editor) { - var cursor = editor.getCursorPos(), - from = {line: cursor.line, ch: 0}, - to = {line: cursor.line, ch: editor.document.getLine(cursor.line).length}; - editor.setSelection(from, to); - } - } - + /** * List of all current (non-destroy()ed) Editor instances. Needed when changing global preferences * that affect all editors, e.g. tabbing or color scheme settings. @@ -1065,7 +1055,6 @@ define(function (require, exports, module) { // Global commands that affect the currently focused Editor instance, wherever it may be CommandManager.register(Strings.CMD_SELECT_ALL, Commands.EDIT_SELECT_ALL, _handleSelectAll); - CommandManager.register("Select Line", Commands.EDIT_SELECT_LINE, _handleSelectLine); // Define public API exports.Editor = Editor; }); diff --git a/src/editor/EditorCommandHandlers.js b/src/editor/EditorCommandHandlers.js index c6d6035351e..9221de26ac8 100644 --- a/src/editor/EditorCommandHandlers.js +++ b/src/editor/EditorCommandHandlers.js @@ -262,6 +262,16 @@ define(function (require, exports, module) { editor._codeMirror.execCommand("indentLess"); } + + function selectLine() { + var editor = EditorManager.getFocusedEditor(); + if (editor) { + var cursor = editor.getCursorPos(), + from = editor.getSelectedText === "" ? {line: cursor.line, ch: 0} : {line: editor.getSelection().start.line, ch: 0}, + to = {line: cursor.line + 1, ch: 0}; + editor.setSelection(from, to); + } + } // Register commands CommandManager.register(Strings.CMD_INDENT, Commands.EDIT_INDENT, indentText); @@ -270,4 +280,5 @@ define(function (require, exports, module) { CommandManager.register(Strings.CMD_DUPLICATE, Commands.EDIT_DUPLICATE, duplicateText); CommandManager.register(Strings.CMD_LINE_UP, Commands.EDIT_LINE_UP, moveLineUp); CommandManager.register(Strings.CMD_LINE_DOWN, Commands.EDIT_LINE_DOWN, moveLineDown); + CommandManager.register("Select Line", Commands.EDIT_SELECT_LINE, selectLine); }); From 1e1b14fae9c02fe531c3bbb9a4770a500eae82a1 Mon Sep 17 00:00:00 2001 From: Chhatoi Pritam Baral Date: Wed, 31 Oct 2012 11:24:52 +0530 Subject: [PATCH 3/5] Ctrl-L on Mac. Now expands selection on repeat --- src/command/Menus.js | 3 ++- src/editor/EditorCommandHandlers.js | 22 ++++++++++------------ src/nls/root/strings.js | 1 + 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/command/Menus.js b/src/command/Menus.js index 1c9a31f1694..c88af87f99d 100644 --- a/src/command/Menus.js +++ b/src/command/Menus.js @@ -864,7 +864,8 @@ define(function (require, exports, module) { */ menu = addMenu(Strings.EDIT_MENU, AppMenuBar.EDIT_MENU); menu.addMenuItem(Commands.EDIT_SELECT_ALL, "Ctrl-A"); - menu.addMenuItem(Commands.EDIT_SELECT_LINE, "Ctrl-L"); + menu.addMenuItem(Commands.EDIT_SELECT_LINE, [{key: "Ctrl-L", platform: "win"}, + {key: "Ctrl-L", platform: "mac"}]); menu.addMenuDivider(); menu.addMenuItem(Commands.EDIT_FIND, "Ctrl-F"); menu.addMenuItem(Commands.EDIT_FIND_IN_FILES, "Ctrl-Shift-F"); diff --git a/src/editor/EditorCommandHandlers.js b/src/editor/EditorCommandHandlers.js index 9860354cfb9..ec80358b0ac 100644 --- a/src/editor/EditorCommandHandlers.js +++ b/src/editor/EditorCommandHandlers.js @@ -262,7 +262,15 @@ define(function (require, exports, module) { editor._codeMirror.execCommand("indentLess"); } - + function selectLine() { + var editor = EditorManager.getFocusedEditor(); + if (editor) { + from = {line: editor.getSelection().start.line, ch: 0}, + to = {line: editor.getSelection().end.line + 1, ch: 0}; + editor.setSelection(from, to); + } + } + /** * Toggles tabs/spaces preferences */ @@ -270,18 +278,8 @@ define(function (require, exports, module) { var useTabs = !Editor.getUseTabChar(); Editor.setUseTabChar(useTabs); CommandManager.get(Commands.TOGGLE_USE_TAB_CHARS).setChecked(useTabs); - - function selectLine() { - var editor = EditorManager.getFocusedEditor(); - if (editor) { - var cursor = editor.getCursorPos(), - from = editor.getSelectedText === "" ? {line: cursor.line, ch: 0} : {line: editor.getSelection().start.line, ch: 0}, - to = {line: cursor.line + 1, ch: 0}; - editor.setSelection(from, to); - } } - // Register commands CommandManager.register(Strings.CMD_INDENT, Commands.EDIT_INDENT, indentText); CommandManager.register(Strings.CMD_UNINDENT, Commands.EDIT_UNINDENT, unidentText); @@ -291,5 +289,5 @@ define(function (require, exports, module) { CommandManager.register(Strings.CMD_LINE_DOWN, Commands.EDIT_LINE_DOWN, moveLineDown); CommandManager.register(Strings.CMD_USE_TAB_CHARS, Commands.TOGGLE_USE_TAB_CHARS, toggleUseTabChars) .setChecked(Editor.getUseTabChar()); - CommandManager.register("Select Line", Commands.EDIT_SELECT_LINE, selectLine); + CommandManager.register(Strings.CMD_SELECT_LINE), Commands.EDIT_SELECT_LINE, selectLine); }); diff --git a/src/nls/root/strings.js b/src/nls/root/strings.js index 02ea2098331..a36b552346e 100644 --- a/src/nls/root/strings.js +++ b/src/nls/root/strings.js @@ -148,6 +148,7 @@ define({ // Edit menu commands "EDIT_MENU" : "Edit", "CMD_SELECT_ALL" : "Select All", + "CMD_SELECT_ALL" : "Select Line", "CMD_FIND" : "Find", "CMD_FIND_IN_FILES" : "Find in Files", "CMD_FIND_NEXT" : "Find Next", From 6c4c4d3fd407b8575ff6abb9577a6dd61a0aaacf Mon Sep 17 00:00:00 2001 From: Chhatoi Pritam Baral Date: Thu, 1 Nov 2012 04:18:14 +0530 Subject: [PATCH 4/5] Corrects mistakes --- src/editor/EditorCommandHandlers.js | 2 +- src/nls/root/strings.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/editor/EditorCommandHandlers.js b/src/editor/EditorCommandHandlers.js index ec80358b0ac..42133800b6e 100644 --- a/src/editor/EditorCommandHandlers.js +++ b/src/editor/EditorCommandHandlers.js @@ -289,5 +289,5 @@ define(function (require, exports, module) { CommandManager.register(Strings.CMD_LINE_DOWN, Commands.EDIT_LINE_DOWN, moveLineDown); CommandManager.register(Strings.CMD_USE_TAB_CHARS, Commands.TOGGLE_USE_TAB_CHARS, toggleUseTabChars) .setChecked(Editor.getUseTabChar()); - CommandManager.register(Strings.CMD_SELECT_LINE), Commands.EDIT_SELECT_LINE, selectLine); + CommandManager.register(Strings.CMD_SELECT_LINE, Commands.EDIT_SELECT_LINE, selectLine); }); diff --git a/src/nls/root/strings.js b/src/nls/root/strings.js index a36b552346e..2e48f2cf478 100644 --- a/src/nls/root/strings.js +++ b/src/nls/root/strings.js @@ -148,7 +148,7 @@ define({ // Edit menu commands "EDIT_MENU" : "Edit", "CMD_SELECT_ALL" : "Select All", - "CMD_SELECT_ALL" : "Select Line", + "CMD_SELECT_LINE" : "Select Line", "CMD_FIND" : "Find", "CMD_FIND_IN_FILES" : "Find in Files", "CMD_FIND_NEXT" : "Find Next", From 7555e141dce08d2fa0a6f6fb1e9d4640a6a3542e Mon Sep 17 00:00:00 2001 From: Chhatoi Pritam Baral Date: Sat, 3 Nov 2012 05:25:41 +0530 Subject: [PATCH 5/5] Corrected syntax and indentation --- src/editor/EditorCommandHandlers.js | 5 +++-- src/nls/root/strings.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/editor/EditorCommandHandlers.js b/src/editor/EditorCommandHandlers.js index bcce9126a9c..85b6811bc0b 100644 --- a/src/editor/EditorCommandHandlers.js +++ b/src/editor/EditorCommandHandlers.js @@ -298,8 +298,9 @@ define(function (require, exports, module) { function selectLine() { var editor = EditorManager.getFocusedEditor(); if (editor) { - var from = {line: editor.getSelection().start.line, ch: 0}, - var to = {line: editor.getSelection().end.line + 1, ch: 0}; + var sel = editor.getSelection(); + var from = {line: sel.start.line, ch: 0}; + var to = {line: sel.end.line + 1, ch: 0}; editor.setSelection(from, to); } } diff --git a/src/nls/root/strings.js b/src/nls/root/strings.js index 5a29aea2333..d7bb109c9be 100644 --- a/src/nls/root/strings.js +++ b/src/nls/root/strings.js @@ -173,7 +173,7 @@ define({ // Edit menu commands "EDIT_MENU" : "Edit", "CMD_SELECT_ALL" : "Select All", - "CMD_SELECT_LINE" : "Select Line", + "CMD_SELECT_LINE" : "Select Line", "CMD_FIND" : "Find", "CMD_FIND_IN_FILES" : "Find in Files", "CMD_FIND_NEXT" : "Find Next",