From 3e350617f40bce900cea15a6aa9c5b7228ae782b Mon Sep 17 00:00:00 2001 From: Vasyl Marchuk Date: Sat, 22 Jun 2024 16:21:26 +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 a770dd481..e77d31570 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) {