Skip to content

Commit 9e5c75b

Browse files
committed
(fix) set cursor position after select tag/emoji
1 parent 82a6d3b commit 9e5c75b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/ChatWindow/Room/Room.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ export default {
415415
filteredUsersTag: [],
416416
selectedUsersTag: [],
417417
textareaCursorPosition: null,
418+
cursorRangePosition: null,
418419
recorder: this.initRecorder(),
419420
isRecording: false,
420421
format: 'mp3'
@@ -645,6 +646,7 @@ export default {
645646
emoji +
646647
this.message.substr(endPosition, this.message.length - 1)
647648
649+
this.cursorRangePosition = position
648650
this.focusTextarea()
649651
},
650652
updateShowUsersTag(query) {
@@ -670,6 +672,8 @@ export default {
670672
671673
this.selectedUsersTag = [...this.selectedUsersTag, { ...user }]
672674
675+
this.cursorRangePosition =
676+
position + user.username.length + space.length + 1
673677
this.focusTextarea()
674678
},
675679
resetFooterList() {
@@ -735,6 +739,16 @@ export default {
735739
if (detectMobile() && disableMobileFocus) return
736740
if (!this.$refs['roomTextarea']) return
737741
this.$refs['roomTextarea'].focus()
742+
743+
if (this.cursorRangePosition) {
744+
setTimeout(() => {
745+
this.$refs['roomTextarea'].setSelectionRange(
746+
this.cursorRangePosition,
747+
this.cursorRangePosition
748+
)
749+
this.cursorRangePosition = null
750+
}, 0)
751+
}
738752
},
739753
preventKeyboardFromClosing() {
740754
if (this.keepKeyboardOpen) this.$refs['roomTextarea'].focus()

0 commit comments

Comments
 (0)