From 054e5f465d8c1288b866df67d7f773157d1f9cdc Mon Sep 17 00:00:00 2001 From: Alex Tideman Date: Thu, 20 Feb 2025 15:29:56 -0600 Subject: [PATCH] Add lineBreakReplacer extention --- src/lib/holocene/code-block.svelte | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lib/holocene/code-block.svelte b/src/lib/holocene/code-block.svelte index 2a13c10b9..5d1b45da4 100644 --- a/src/lib/holocene/code-block.svelte +++ b/src/lib/holocene/code-block.svelte @@ -91,6 +91,16 @@ $: value = formatValue({ value: content, language }); + const lineBreakReplacer = EditorView.updateListener.of((update) => { + if (editable) return; + const newText = update.state.doc.toString().replace(/\\n/g, '\n'); + if (newText !== update.state.doc.toString()) { + update.view.dispatch({ + changes: { from: 0, to: update.state.doc.length, insert: newText }, + }); + } + }); + const createEditorView = (isDark: boolean): EditorView => { return new EditorView({ parent: editor, @@ -120,6 +130,7 @@ EditorState.readOnly.of(!editable), EditorView.editable.of(editable), EditorView.contentAttributes.of({ 'aria-label': label }), + lineBreakReplacer, ]; if (language === 'json') {