Merge branch 'stable-3.13' into stable-3.14 * stable-3.13: Preserve line terminator upon edits Change-Id: Iad7d6ccdf2b0c000e96fb1f11c24f4ee6b5c1be7
diff --git a/web/element/codemirror-element.ts b/web/element/codemirror-element.ts index 7b1bf5a..eb014ac 100644 --- a/web/element/codemirror-element.ts +++ b/web/element/codemirror-element.ts
@@ -60,6 +60,8 @@ @query('#result') result!: HTMLElement; + private lineTerminator?: string; + private initialized = false; private onResize: (() => void) | null = null; @@ -122,6 +124,8 @@ if (this.initialized) return; this.initialized = true; + this.lineTerminator = this.fileContent?.includes('\r\n') ? '\r\n' : '\n'; + const editor = new EditorView({ state: EditorState.create({ doc: this.fileContent ?? '', @@ -151,7 +155,7 @@ if (update.docChanged) { this.dispatchEvent( new CustomEvent('content-change', { - detail: {value: update.state.doc.toString()}, + detail: {value: update.state.doc.toJSON().join(this.lineTerminator)}, bubbles: true, composed: true, })