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

Commit

Permalink
Merge remote-tracking branch 'origin/master' into nj/inline-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
njx committed Apr 4, 2012
2 parents 3b319c9 + 05888b1 commit 683ac5b
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,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 @@ -253,6 +252,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 @@ -346,6 +351,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 @@ -768,6 +791,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}
Expand Down

0 comments on commit 683ac5b

Please sign in to comment.