From e9928ee53e6bd74af37e90acc57087bbdac412ba Mon Sep 17 00:00:00 2001 From: Matt McCutchen Date: Tue, 7 Aug 2018 17:24:10 -0400 Subject: [PATCH] codemirror: EditorChangeCancellable.update is undefined for changes coming from undo/redo. --- types/codemirror/index.d.ts | 5 +++-- types/codemirror/test/index.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/types/codemirror/index.d.ts b/types/codemirror/index.d.ts index 6dbfef6e60..f71f741659 100644 --- a/types/codemirror/index.d.ts +++ b/types/codemirror/index.d.ts @@ -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; } diff --git a/types/codemirror/test/index.ts b/types/codemirror/test/index.ts index 9b9231b25c..431a20efb6 100644 --- a/types/codemirror/test/index.ts +++ b/types/codemirror/test/index.ts @@ -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();