Skip to content

Commit

Permalink
#2387 Two emoji picker issues (#2400)
Browse files Browse the repository at this point in the history
* fix issue No. 1

* make sure emoticon is added to the cursor position

* add comment

* comment update
  • Loading branch information
SebinSong authored Oct 28, 2024
1 parent b98eb74 commit 9ef7930
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
13 changes: 11 additions & 2 deletions frontend/views/containers/chatroom/Emoticons.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template lang='pug'>
.c-picker(:class='{ "is-active": isActive }' @click='clickBackDrop')
.c-picker-wrapper(:style='position')
picker(@select='select' :data='emoji' :show-preview='false')
.c-picker-wrapper(ref='pickerWrapper' :style='position')
picker(@select='select' :data='emoji' :show-preview='false' :auto-focus='true')
</template>

<script>
Expand Down Expand Up @@ -53,6 +53,8 @@ export default ({
}
this.lastFocus = document.activeElement
this.isActive = true
this.$nextTick(this.focusSearch)
},
select (emoticon) {
sbp('okTurtles.events/emit', SELECT_EMOTICON, emoticon)
Expand Down Expand Up @@ -105,6 +107,13 @@ export default ({
this.closeEmoticonDlg()
}
this.debouncedSetPosition()
},
focusSearch () {
// It appears that there is no component-level method provided to focus the search. So using browser API instead here.
// (reference: https://github.com/serebrov/emoji-mart-vue/blob/master/src/components/search.vue)
const searchInputEl = this.$refs.pickerWrapper.querySelector('.emoji-mart-search input')
searchInputEl && searchInputEl.focus()
}
},
watch: {
Expand Down
7 changes: 6 additions & 1 deletion frontend/views/containers/chatroom/SendArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,12 @@ export default ({
}
},
selectEmoticon (emoticon) {
this.$refs.textarea.value = this.$refs.textarea.value + emoticon.native
// Making sure the emoticon is added to the cursor position
const inputEl = this.$refs.textarea
const valuePrev = inputEl.value.slice(0, inputEl.selectionStart) || ''
const valueAfter = inputEl.value.slice(inputEl.selectionEnd) || ''
inputEl.value = valuePrev + emoticon.native + valueAfter
this.closeEmoticon()
this.updateTextWithLines()
},
Expand Down

0 comments on commit 9ef7930

Please sign in to comment.