From 0c902e3f6f622de13cbd20f0a188497cc6dd7330 Mon Sep 17 00:00:00 2001 From: Vasyl Marchuk Date: Sat, 22 Jun 2024 15:25:53 +0300 Subject: [PATCH] Reload `@document` in `CodeMirror` component when `@lineSeparator` changes --- app/components/code-mirror.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/components/code-mirror.ts b/app/components/code-mirror.ts index a770dd481b..e77d315703 100644 --- a/app/components/code-mirror.ts +++ b/app/components/code-mirror.ts @@ -349,6 +349,19 @@ export default class CodeMirrorComponent extends Component { this.renderedView?.dispatch({ effects: compartment?.reconfigure(handlerMethod ? await handlerMethod(newValue as undefined, this.args, optionName) : []), }); + + // some options need the document to be re-loaded after being applied + if (['lineSeparator'].includes(optionName)) { + this.renderedView?.dispatch( + this.renderedView?.state.update({ + changes: { + from: 0, + to: this.renderedView.state.doc.length, + insert: this.args.document, + }, + }), + ); + } } @action async renderEditor(element: Element) {