Skip to content

Commit

Permalink
fix cursor adjustment done by replaceRange
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Feb 8, 2011
1 parent a603652 commit b327364
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/codemirror.js
Expand Up @@ -951,23 +951,21 @@ var CodeMirror = (function() {
while (pos < indentation) {++pos; indentString += " ";}
}

var adjustFrom = sel.from.line == n && sel.from.ch <= curSpaceString.length,
adjustTo = sel.to.line == n && sel.to.ch <= curSpaceString.length;
replaceRange(indentString, {line: n, ch: 0}, {line: n, ch: curSpaceString.length});
if (adjustFrom || adjustTo) {
var pos = {line: n, ch: indentString.length};
setSelection(adjustFrom ? pos : sel.from, adjustTo ? pos : sel.to);
}
}

function replaceRange(code, from, to) {
from = clipPos(from);
if (!to) to = from; else to = clipPos(to);
code = splitLines(code);
function adjustPos(pos) {
if (posLess(pos, from)) return pos;
if (posLess(pos, to)) return end;
if (pos.line == to.line) return {line: end.line, ch: pos.ch + end.ch - to.ch};
return {line: pos.line + end.line - to.line, ch: pos.ch};
var line = pos.line + code.length - (to.line - from.line) - 1;
var ch = pos.ch;
if (pos.line == to.line)
ch += code[0].length - (to.ch - (to.line == from.line ? from.ch : 0));
return {line: line, ch: ch};
}
var end;
replaceRange1(code, from, to, function(end1) {
Expand Down

0 comments on commit b327364

Please sign in to comment.