From 9aab0546a379831f940470a526453b485dbf3e2a Mon Sep 17 00:00:00 2001 From: Lance Campbell Date: Thu, 22 Aug 2013 09:15:36 -0700 Subject: [PATCH 1/3] Update toggling Highlight Active Line command --- src/editor/Editor.js | 7 ++++++- src/editor/EditorOptionHandlers.js | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 25759ade572..4c80a7a450d 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -1550,10 +1550,15 @@ define(function (require, exports, module) { /** * Sets show active line option and reapply it to all open editors. * @param {boolean} value + * @param {Editor} Current editor */ - Editor.setShowActiveLine = function (value) { + Editor.setShowActiveLine = function (value, editor) { _styleActiveLine = value; _setEditorOptionAndPref(value, "styleActiveLine", "styleActiveLine"); + + if (editor.hasSelection()) { + editor._codeMirror.setOption("styleActiveLine", false); + } }; /** @type {boolean} Returns true if show active line is enabled for all editors */ diff --git a/src/editor/EditorOptionHandlers.js b/src/editor/EditorOptionHandlers.js index d51776695c2..d0874f935a9 100644 --- a/src/editor/EditorOptionHandlers.js +++ b/src/editor/EditorOptionHandlers.js @@ -29,6 +29,7 @@ define(function (require, exports, module) { var AppInit = require("utils/AppInit"), Editor = require("editor/Editor").Editor, + EditorManager = require("editor/EditorManager"), Commands = require("command/Commands"), CommandManager = require("command/CommandManager"), Strings = require("strings"); @@ -48,7 +49,7 @@ define(function (require, exports, module) { * Activates/Deactivates showing active line option */ function _toggleActiveLine() { - Editor.setShowActiveLine(!Editor.getShowActiveLine()); + Editor.setShowActiveLine(!Editor.getShowActiveLine(), EditorManager.getCurrentFullEditor()); CommandManager.get(Commands.TOGGLE_ACTIVE_LINE).setChecked(Editor.getShowActiveLine()); } From 3222b1fb644949a54c72818910a7fdb59846451a Mon Sep 17 00:00:00 2001 From: Lance Campbell Date: Thu, 22 Aug 2013 09:44:15 -0700 Subject: [PATCH 2/3] Add in cursorActivity listener and handler --- src/editor/Editor.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 4c80a7a450d..b2742f64f87 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -250,6 +250,16 @@ define(function (require, exports, module) { } } + function _handleCursorActivity(jqEvent, editor, event) { + if (editor.hasSelection()) { + if (editor._codeMirror.getOption("styleActiveLine")) { + editor._codeMirror.setOption("styleActiveLine", false); + } + } else { + editor._codeMirror.setOption("styleActiveLine", _styleActiveLine); + } + } + function _handleKeyEvents(jqEvent, editor, event) { _checkElectricChars(jqEvent, editor, event); @@ -382,6 +392,7 @@ define(function (require, exports, module) { this._installEditorListeners(); $(this) + .on("cursorActivity", _handleCursorActivity) .on("keyEvent", _handleKeyEvents) .on("change", this._handleEditorChange.bind(this)); From aea644d8ae9c30b0c56ac10658b58a1fa7a8962b Mon Sep 17 00:00:00 2001 From: Lance Campbell Date: Fri, 23 Aug 2013 06:26:27 -0700 Subject: [PATCH 3/3] Added JSDoc and other comments --- src/editor/Editor.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index b2742f64f87..28a6ee53c3d 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -249,8 +249,16 @@ define(function (require, exports, module) { } } } - + + /** + * @private + * Handle any cursor movement in editor, including selecting and unselecting text. + * @param {jQueryObject} jqEvent jQuery event object + * @param {Editor} editor Current, focused editor (main or inline) + * @param {!Event} event + */ function _handleCursorActivity(jqEvent, editor, event) { + // If there is a selection in the editor, temporarily hide Active Line Highlight if (editor.hasSelection()) { if (editor._codeMirror.getOption("styleActiveLine")) { editor._codeMirror.setOption("styleActiveLine", false); @@ -1561,7 +1569,7 @@ define(function (require, exports, module) { /** * Sets show active line option and reapply it to all open editors. * @param {boolean} value - * @param {Editor} Current editor + * @param {Editor} editor Current, focused editor (main or inline) */ Editor.setShowActiveLine = function (value, editor) { _styleActiveLine = value;