Skip to content

Commit

Permalink
fix: Unable to add emoji exactly where the cursor is at (#5865)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
iamsivin committed Dec 5, 2022
1 parent 0b5c82a commit 613fb0b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/javascript/dashboard/components/widgets/WootWriter/Editor.vue
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -60,13 +60,15 @@
class="input"
:is-private="isOnPrivateNote"
:placeholder="messagePlaceHolder"
:update-selection-with="updateEditorSelectionWith"
:min-height="4"
@typing-off="onTypingOff"
@typing-on="onTypingOn"
@focus="onFocus"
@blur="onBlur"
@toggle-user-mention="toggleUserMention"
@toggle-canned-menu="toggleCannedMenu"
@clear-selection="clearEditorSelection"
/>
</div>
<div v-if="hasAttachments" class="attachment-preview-box" @paste="onPaste">
Expand Down Expand Up @@ -215,6 +217,7 @@ export default {
ccEmails: '',
doAutoSaveDraft: () => {},
showWhatsAppTemplatesModal: false,
updateEditorSelectionWith: '',
};
},
computed: {
Expand Down Expand Up @@ -707,8 +710,26 @@ export default {
}
this.$nextTick(() => this.$refs.messageInput.focus());
},
clearEditorSelection() {
this.updateEditorSelectionWith = '';
},
insertEmoji(emoji, selectionStart, selectionEnd) {
const { message } = this;
const newMessage =
message.slice(0, selectionStart) +
emoji +
message.slice(selectionEnd, message.length);
this.message = newMessage;
},
emojiOnClick(emoji) {
this.message = `${this.message}${emoji} `;
if (this.showRichContentEditor) {
this.updateEditorSelectionWith = emoji;
this.onFocus();
}
if (!this.showRichContentEditor) {
const { selectionStart, selectionEnd } = this.$refs.messageInput.$el;
this.insertEmoji(emoji, selectionStart, selectionEnd);
}
},
clearMessage() {
this.message = '';
Expand Down

0 comments on commit 613fb0b

Please sign in to comment.