Skip to content

Commit

Permalink
Changed monaco-adapter to respect line endings when calculating posit…
Browse files Browse the repository at this point in the history
…ions (#303)

When monaco was not using '\n' as its line ending then the calculations for text positions were all incorrect which caused the creation of faulty TextOps

This simply uses the monaco.getModel().getEOF() to access the currently used line feed and calculate positions based on that.
  • Loading branch information
Pascal Roessner authored and mikelehen committed Jun 18, 2018
1 parent 2c4bebf commit 9e70ccd
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/monaco-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ firepad.MonacoAdapter = (function() {
MonacoAdapter.prototype.operationFromMonacoChange = function(change) {
text = change.changes[0].text;
start = this.indexFromPos(change.changes[0].range, 'start');
restLength = this.lastDocLines.join('\n').length - start;
restLength = this.lastDocLines.join(this.monacoModel.getEOL()).length - start;
text_ins = change.changes[0].text;
rangeLen = change.changes[0].rangeLength;

if (change.changes[0].rangeLength > 0) {
restLength -= rangeLen;
text = this.lastDocLines.join('\n')
text = this.lastDocLines.join(this.monacoModel.getEOL())
.slice(start, start+rangeLen);
}

Expand Down Expand Up @@ -137,7 +137,7 @@ firepad.MonacoAdapter = (function() {
if (index <= line.length) {
break;
}
index -= line.length + 1;
index -= line.length + this.monacoModel.getEOL().length;
}
return {
row: row + 1,
Expand All @@ -154,12 +154,12 @@ firepad.MonacoAdapter = (function() {
index = 0;
if (upto === 'start') {
for (row = 1; row < range.startLineNumber; row++) {
index += lines[row-1].length + 1
index += lines[row-1].length + this.monacoModel.getEOL().length;
}
return index + range.startColumn -1;
} else {
for (row = 1; row < range.endLineNumber; row++) {
index += lines[row-1].length + 1
index += lines[row-1].length + this.monacoModel.getEOL().length;
}
return index + range.endColumn -1;
}
Expand Down

0 comments on commit 9e70ccd

Please sign in to comment.