Skip to content

Commit 3682197

Browse files
committed
Make posFromIndex and indexFromPos take lineSeparator into account
Closes codemirror#3905
1 parent eca7fd6 commit 3682197

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/codemirror.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7646,9 +7646,9 @@
76467646
},
76477647

76487648
posFromIndex: function(off) {
7649-
var ch, lineNo = this.first;
7649+
var ch, lineNo = this.first, sepSize = this.lineSeparator().length;
76507650
this.iter(function(line) {
7651-
var sz = line.text.length + 1;
7651+
var sz = line.text.length + sepSize;
76527652
if (sz > off) { ch = off; return true; }
76537653
off -= sz;
76547654
++lineNo;
@@ -7659,8 +7659,9 @@
76597659
coords = clipPos(this, coords);
76607660
var index = coords.ch;
76617661
if (coords.line < this.first || coords.ch < 0) return 0;
7662+
var sepSize = this.lineSeparator().length;
76627663
this.iter(this.first, coords.line, function (line) {
7663-
index += line.text.length + 1;
7664+
index += line.text.length + sepSize;
76647665
});
76657666
return index;
76667667
},

0 commit comments

Comments
 (0)