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

Commit 5829ef7

Browse files
committed
Merge pull request #4878 from lkcampbell/fix-issue-4778
Fix issue 4778: Do not show Active Line Highlight when editor has selection
2 parents 55e0995 + aea644d commit 5829ef7

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/editor/Editor.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,25 @@ define(function (require, exports, module) {
249249
}
250250
}
251251
}
252-
252+
253+
/**
254+
* @private
255+
* Handle any cursor movement in editor, including selecting and unselecting text.
256+
* @param {jQueryObject} jqEvent jQuery event object
257+
* @param {Editor} editor Current, focused editor (main or inline)
258+
* @param {!Event} event
259+
*/
260+
function _handleCursorActivity(jqEvent, editor, event) {
261+
// If there is a selection in the editor, temporarily hide Active Line Highlight
262+
if (editor.hasSelection()) {
263+
if (editor._codeMirror.getOption("styleActiveLine")) {
264+
editor._codeMirror.setOption("styleActiveLine", false);
265+
}
266+
} else {
267+
editor._codeMirror.setOption("styleActiveLine", _styleActiveLine);
268+
}
269+
}
270+
253271
function _handleKeyEvents(jqEvent, editor, event) {
254272
_checkElectricChars(jqEvent, editor, event);
255273

@@ -382,6 +400,7 @@ define(function (require, exports, module) {
382400
this._installEditorListeners();
383401

384402
$(this)
403+
.on("cursorActivity", _handleCursorActivity)
385404
.on("keyEvent", _handleKeyEvents)
386405
.on("change", this._handleEditorChange.bind(this));
387406

@@ -1550,10 +1569,15 @@ define(function (require, exports, module) {
15501569
/**
15511570
* Sets show active line option and reapply it to all open editors.
15521571
* @param {boolean} value
1572+
* @param {Editor} editor Current, focused editor (main or inline)
15531573
*/
1554-
Editor.setShowActiveLine = function (value) {
1574+
Editor.setShowActiveLine = function (value, editor) {
15551575
_styleActiveLine = value;
15561576
_setEditorOptionAndPref(value, "styleActiveLine", "styleActiveLine");
1577+
1578+
if (editor.hasSelection()) {
1579+
editor._codeMirror.setOption("styleActiveLine", false);
1580+
}
15571581
};
15581582

15591583
/** @type {boolean} Returns true if show active line is enabled for all editors */

src/editor/EditorOptionHandlers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ define(function (require, exports, module) {
2929

3030
var AppInit = require("utils/AppInit"),
3131
Editor = require("editor/Editor").Editor,
32+
EditorManager = require("editor/EditorManager"),
3233
Commands = require("command/Commands"),
3334
CommandManager = require("command/CommandManager"),
3435
Strings = require("strings");
@@ -48,7 +49,7 @@ define(function (require, exports, module) {
4849
* Activates/Deactivates showing active line option
4950
*/
5051
function _toggleActiveLine() {
51-
Editor.setShowActiveLine(!Editor.getShowActiveLine());
52+
Editor.setShowActiveLine(!Editor.getShowActiveLine(), EditorManager.getCurrentFullEditor());
5253
CommandManager.get(Commands.TOGGLE_ACTIVE_LINE).setChecked(Editor.getShowActiveLine());
5354
}
5455

0 commit comments

Comments
 (0)