From 43443305e691c8895bfa5dfe225a377e2d4626b8 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Thu, 15 Feb 2024 20:54:54 +0100 Subject: [PATCH] basic bold function --- .../components/MarkdownEditorComponent.vue | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/vue/src/components/MarkdownEditorComponent.vue b/vue/src/components/MarkdownEditorComponent.vue index c231a1986..fdca881b7 100644 --- a/vue/src/components/MarkdownEditorComponent.vue +++ b/vue/src/components/MarkdownEditorComponent.vue @@ -2,7 +2,8 @@

EDITOR

- Test + Heading + B
@@ -176,6 +177,33 @@ export default { }) this.editor_view.dispatch(transaction) + }, + bold() { + const transaction = this.editor_view.state.changeByRange((range) => { + + if (range.anchor === range.head) { + console.log('nothing selected --> nothing bold') + } else { + let selected_text = this.editor_view.state.sliceDoc(range.from, range.to) + + let new_text = `**${selected_text}**` + + const changes = { + from: range.from, + to: range.to, + insert: new_text, + } + + return {changes, range: EditorSelection.range(range.anchor + 2, range.head + 2)} + } + + + }) + + this.editor_view.dispatch(transaction) + }, + heading(editor, heading_size) { + } }, }