From 613fb0b06425fd61d4808375c0ab019c13cc1ca6 Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Mon, 5 Dec 2022 11:16:00 +0530 Subject: [PATCH] fix: Unable to add emoji exactly where the cursor is at (#5865) * fix: Unable to add emoji exactly where the cursor is at * chore: Minor fixes * chore: Review fixes * chore: Code clean up * chore: Review fixes * chore: Minor fixes * chore: Review fixes --- .../components/widgets/WootWriter/Editor.vue | 20 ++++++++++++++++ .../widgets/conversation/ReplyBox.vue | 23 ++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/app/javascript/dashboard/components/widgets/WootWriter/Editor.vue b/app/javascript/dashboard/components/widgets/WootWriter/Editor.vue index a00a3bf5a..bd47074ce 100644 --- a/app/javascript/dashboard/components/widgets/WootWriter/Editor.vue +++ b/app/javascript/dashboard/components/widgets/WootWriter/Editor.vue @@ -65,6 +65,7 @@ export default { placeholder: { type: String, default: '' }, isPrivate: { type: Boolean, default: false }, enableSuggestions: { type: Boolean, default: true }, + updateSelectionWith: { type: String, default: '' }, }, data() { return { @@ -162,6 +163,25 @@ export default { isPrivate() { this.reloadState(); }, + + updateSelectionWith(newValue, oldValue) { + if (!this.editorView) { + return null; + } + if (newValue !== oldValue) { + if (this.updateSelectionWith !== '') { + const node = this.editorView.state.schema.text( + this.updateSelectionWith + ); + const tr = this.editorView.state.tr.replaceSelectionWith(node); + this.editorView.focus(); + this.state = this.editorView.state.apply(tr); + this.emitOnChange(); + this.$emit('clear-selection'); + } + } + return null; + }, }, created() { this.state = createState(this.value, this.placeholder, this.plugins); diff --git a/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue b/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue index e7c825752..fdbb2fbdd 100644 --- a/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue +++ b/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue @@ -60,6 +60,7 @@ class="input" :is-private="isOnPrivateNote" :placeholder="messagePlaceHolder" + :update-selection-with="updateEditorSelectionWith" :min-height="4" @typing-off="onTypingOff" @typing-on="onTypingOn" @@ -67,6 +68,7 @@ @blur="onBlur" @toggle-user-mention="toggleUserMention" @toggle-canned-menu="toggleCannedMenu" + @clear-selection="clearEditorSelection" />