From c94ba165654293cfb3f66f2d9bb7a3c9c29dd51c Mon Sep 17 00:00:00 2001 From: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> Date: Tue, 29 Nov 2022 06:16:55 -0800 Subject: [PATCH] fix: Updates logic to insert canned response into editor (#5880) * fix: Updates logic to insert canned response into editor * Removes commented code * Parse incoming canned text as markdown --- .../components/widgets/WootWriter/Editor.vue | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/app/javascript/dashboard/components/widgets/WootWriter/Editor.vue b/app/javascript/dashboard/components/widgets/WootWriter/Editor.vue index ee3337cf9..a00a3bf5a 100644 --- a/app/javascript/dashboard/components/widgets/WootWriter/Editor.vue +++ b/app/javascript/dashboard/components/widgets/WootWriter/Editor.vue @@ -233,7 +233,9 @@ export default { node ); this.state = this.editorView.state.apply(tr); - return this.emitOnChange(); + this.emitOnChange(); + + return false; }, insertCannedResponse(cannedItem) { @@ -241,22 +243,26 @@ export default { return null; } - const tr = this.editorView.state.tr.insertText( - cannedItem, - this.range.from, - this.range.to + let from = this.range.from - 1; + let node = addMentionsToMarkdownParser(defaultMarkdownParser).parse( + cannedItem ); + + if (node.childCount === 1) { + node = this.editorView.state.schema.text(cannedItem); + from = this.range.from; + } + + const tr = this.editorView.state.tr.replaceWith( + from, + this.range.to, + node + ); + this.state = this.editorView.state.apply(tr); this.emitOnChange(); - // Hacky fix for #5501 - this.state = createState( - this.contentFromEditor, - this.placeholder, - this.plugins - ); - this.editorView.updateState(this.state); - this.focusEditorInputField(); + tr.scrollIntoView(); return false; },