Skip to content

Commit 3d5a29c

Browse files
authored
#2577 - Paste issue on iOS Safari (#2674)
* improve the fix in the paste handler * fix typo * update comment * cypress: fix early detroyal issue * add comment
1 parent de173cb commit 3d5a29c

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

frontend/views/containers/chatroom/SendArea.vue

+9-15
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
@keydown.ctrl='isNextLine'
7171
@keydown='handleKeydown'
7272
@keyup='handleKeyup'
73+
@input='config.debouncedHandleInput'
7374
@paste='handlePaste'
7475
v-bind='$attrs'
7576
)
@@ -282,7 +283,7 @@ import {
282283
} from '@model/contracts/shared/constants.js'
283284
import { CHAT_ATTACHMENT_SIZE_LIMIT, IMAGE_ATTACHMENT_MAX_SIZE } from '~/frontend/utils/constants.js'
284285
import { OPEN_MODAL, CHATROOM_USER_TYPING, CHATROOM_USER_STOP_TYPING } from '@utils/events.js'
285-
import { uniq, throttle, cloneDeep } from '@model/contracts/shared/giLodash.js'
286+
import { uniq, throttle, cloneDeep, debounce } from '@model/contracts/shared/giLodash.js'
286287
import {
287288
injectOrStripSpecialChar,
288289
injectOrStripLink,
@@ -357,7 +358,12 @@ export default ({
357358
typingUsers: []
358359
},
359360
config: {
360-
messageMaxChar: CHATROOM_MAX_MESSAGE_LEN
361+
messageMaxChar: CHATROOM_MAX_MESSAGE_LEN,
362+
// NOTE: Below is a fix for the issue #2369 and #2577, which are issues related to paste action on mobile devices.
363+
// <textarea /> in this component handles two-way binding of the entered text using 'keydown' and 'keyup' events instead of the traditional v-model due to
364+
// various functional requirements. But 'paste' action on mobile is not detected by them because they are done via touching the menu on the screen instead, not by pressing keyboard keys.
365+
// We can detect this pasted content by running this.updateTextWithLines() for 'input' event. But this does not need to be done for every key stroke, hence the debounce.
366+
debouncedHandleInput: debounce(this.updateTextArea, 250)
361367
},
362368
typingUserTimeoutIds: {},
363369
throttledEmitUserTypingEvent: throttle(this.emitUserTypingEvent, 500),
@@ -565,18 +571,6 @@ export default ({
565571
handlePaste (e) {
566572
if (e.clipboardData.files.length > 0) {
567573
this.fileAttachmentHandler(e.clipboardData.files, true)
568-
return
569-
}
570-
571-
// fix for the edge-case related to 'paste' action when nothing has been typed
572-
// (reference: https://github.com/okTurtles/group-income/issues/2369)
573-
const currVal = this.$refs.textarea.value
574-
575-
if (!currVal) {
576-
e.preventDefault()
577-
const pastedText = e.clipboardData.getData('text')
578-
this.$refs.textarea.value = pastedText
579-
this.updateTextArea()
580574
}
581575
},
582576
addSelectedMention (index) {
@@ -630,7 +624,7 @@ export default ({
630624
return true
631625
},
632626
updateTextArea () {
633-
if (!this.updateTextWithLines()) {
627+
if (!this.$refs.textarea || !this.updateTextWithLines()) {
634628
// dont calculate again when the value is the same (ex: happens on shift+enter)
635629
return false
636630
}

0 commit comments

Comments
 (0)