diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 37c1af5534c..4ef71074ece 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -189,7 +189,6 @@ define(function (require, exports, module) { findBarTextField.get(0).select(); } - /** * Creates a new CodeMirror editor instance bound to the given Document. The Document need not have * a "master" Editor realized yet, even if makeMasterEditor is false; in that case, the first time @@ -249,6 +248,12 @@ define(function (require, exports, module) { CodeMirror.commands.delCharRight(instance); } }, + "Ctrl-A": function () { + self._selectAllVisible(); + }, + "Cmd-A": function () { + self._selectAllVisible(); + }, "Ctrl-F": _launchFind, "Cmd-F": _launchFind, "F3": "findNext", @@ -342,6 +347,24 @@ define(function (require, exports, module) { }); }; + + /** + * Handles Select All specially when we have a visible range in order to work around + * bugs in CodeMirror when lines are hidden. + */ + Editor.prototype._selectAllVisible = function () { + var startLine, endLine; + if (this._visibleRange) { + startLine = this._visibleRange.startLine; + endLine = this._visibleRange.endLine; + } else { + startLine = 0; + endLine = this.lineCount() - 1; + } + this.setSelection({line: startLine, ch: 0}, + {line: endLine, ch: this.getLineText(endLine).length}); + }; + Editor.prototype._applyChangesToEditor = function (editor, changeList) { // FUTURE: Technically we should add a replaceRange() method to Document and go through // that instead of talking to the given editor directly. However, we need to access @@ -770,6 +793,15 @@ define(function (require, exports, module) { return $(this._codeMirror.getWrapperElement()).is(":visible"); }; + /** + * Returns the text of the given line. + * @param {number} The zero-based number of the line to retrieve. + * @return {string} The contents of the line. + */ + Editor.prototype.getLineText = function (num) { + return this._codeMirror.getLine(num); + }; + /** * The Document we're bound to * @type {!Document}