Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
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
34 changes: 33 additions & 1 deletion src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
*/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing @return docs

Editor.prototype.getLineText = function (num) {
return this._codeMirror.getLine(num);
};

/**
* The Document we're bound to
* @type {!Document}
Expand Down