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

Commit

Permalink
Make anti-orphans code multi cursor compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Gerber committed Oct 4, 2014
1 parent 2a78b2e commit 5423209
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,17 +415,23 @@ define(function (require, exports, module) {
var keyStr = String.fromCharCode(event.which || event.keyCode);

if (/[\]\{\}\)]/.test(keyStr)) {
// If all text before the cursor is whitespace, auto-indent it
var instance = this._codeMirror,
cursor = this.getCursorPos(),
lineStr = instance.getLine(cursor.line);

if (lineStr && !/\S/.test(lineStr)) {
// if the line is all whitespace, move the cursor to the end of the line
// before indenting so that embedded whitespace such as indents are not
// orphaned to the right of the electric char being inserted
this.setCursorPos(cursor.line, this.document.getLine(cursor.line).length);
}
var self = this,
instance = this._codeMirror,
selections,
lineStr;

selections = this.getSelections().map(function (sel) {
lineStr = instance.getLine(sel.end.line);

if (lineStr && !/\S/.test(lineStr)) {
// if the line is all whitespace, move the cursor to the end of the line
// before indenting so that embedded whitespace such as indents are not
// orphaned to the right of the electric char being inserted
sel.end.ch = self.document.getLine(sel.end.line).length;
}
return sel;
});
this.setSelections(selections);
}
};

Expand Down

0 comments on commit 5423209

Please sign in to comment.