mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-27 09:53:13 +00:00
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:
parent
22ee7d6da2
commit
74d9937816
2 changed files with 8 additions and 4 deletions
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue