Merge pull request #6536 from overleaf/bg-cm6-size-check

Add editor max doc length checks to codemirror

GitOrigin-RevId: 0a458fc3aa23f22b078c6607ee4347bc76c371e9
This commit is contained in:
Timothée Alby 2022-02-02 11:25:06 +01:00 committed by Copybot
parent 22ee7d6da2
commit 74d9937816
2 changed files with 8 additions and 4 deletions

View file

@ -368,7 +368,7 @@ export default ShareJsDoc = (function () {
attachToCM(cm) {
this._attachToEditor('CM', cm, () => {
this._doc.attach_cm(cm, false)
this._doc.attach_cm(cm, false, window.maxDocLength)
})
}
@ -381,7 +381,7 @@ export default ShareJsDoc = (function () {
attachToCM6(cm6) {
this._attachToEditor('CM6', cm6, () => {
cm6.attachShareJs(this._doc)
cm6.attachShareJs(this._doc, false, window.maxDocLength)
})
}

View file

@ -1506,7 +1506,7 @@ define(['ace/ace','crypto-js/sha1'], function (_ignore, CryptoJSSHA1) {
return;
}
if (maxDocLength != null && editorDoc.getValue().length > maxDocLength) {
if (maxDocLength != null && editorDoc.getValue().length >= maxDocLength) {
doc.emit('error', new Error('document length is greater than maxDocLength'));
return;
}
@ -1629,7 +1629,7 @@ define(['ace/ace','crypto-js/sha1'], function (_ignore, CryptoJSSHA1) {
// a custom `origin: 'remote'` which may conflict.
// Perma link of the docs at the time of writing this note:
// https://web.archive.org/web/20201029163528/https://codemirror.net/doc/manual.html#selection_origin
window.sharejs.extendDoc('attach_cm', function (editor, keepEditorContents) {
window.sharejs.extendDoc('attach_cm', function (editor, keepEditorContents, maxDocLength) {
if (!this.provides.text) {
throw new Error('Only text documents can be attached to CodeMirror2');
}
@ -1666,6 +1666,10 @@ define(['ace/ace','crypto-js/sha1'], function (_ignore, CryptoJSSHA1) {
// this change has been injected via sharejs
return;
}
if (maxDocLength != null && editorDoc.getValue().length >= maxDocLength) {
sharedoc.emit('error', new Error('document length is greater than maxDocLength'));
return;
}
var fromUndo = (change.origin === 'undo')
applyCMToShareJS(editorDoc, change, sharedoc, fromUndo);
return check();