codemirror: EditorChangeCancellable.update is undefined for changes

coming from undo/redo.
This commit is contained in:
Matt McCutchen
2018-08-07 17:24:10 -04:00
parent 2d432d6582
commit e9928ee53e
2 changed files with 12 additions and 2 deletions

View File

@@ -716,8 +716,9 @@ declare namespace CodeMirror {
}
interface EditorChangeCancellable extends CodeMirror.EditorChange {
/** may be used to modify the change. All three arguments to update are optional, and can be left off to leave the existing value for that field intact. */
update(from?: CodeMirror.Position, to?: CodeMirror.Position, text?: string[]): void;
/** may be used to modify the change. All three arguments to update are optional, and can be left off to leave the existing value for that field intact.
If the change came from undo/redo, `update` is undefined and the change cannot be modified. */
update?(from?: CodeMirror.Position, to?: CodeMirror.Position, text?: string[]): void;
cancel(): void;
}

View File

@@ -67,6 +67,15 @@ myCodeMirror.on(
(instance: CodeMirror.Editor, line: CodeMirror.LineHandle, element: HTMLElement) => { }
);
myCodeMirror.on(
"beforeChange",
(instance: CodeMirror.Editor, change: CodeMirror.EditorChangeCancellable) => {
// $ExpectError
change.update();
if (change.update != null) change.update();
}
);
CodeMirror.registerHelper("lint", "javascript", {});
myCodeMirror.isReadOnly();