|
70 | 70 | @keydown.ctrl='isNextLine'
|
71 | 71 | @keydown='handleKeydown'
|
72 | 72 | @keyup='handleKeyup'
|
| 73 | + @input='config.debouncedHandleInput' |
73 | 74 | @paste='handlePaste'
|
74 | 75 | v-bind='$attrs'
|
75 | 76 | )
|
@@ -282,7 +283,7 @@ import {
|
282 | 283 | } from '@model/contracts/shared/constants.js'
|
283 | 284 | import { CHAT_ATTACHMENT_SIZE_LIMIT, IMAGE_ATTACHMENT_MAX_SIZE } from '~/frontend/utils/constants.js'
|
284 | 285 | 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' |
286 | 287 | import {
|
287 | 288 | injectOrStripSpecialChar,
|
288 | 289 | injectOrStripLink,
|
@@ -357,7 +358,12 @@ export default ({
|
357 | 358 | typingUsers: []
|
358 | 359 | },
|
359 | 360 | 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) |
361 | 367 | },
|
362 | 368 | typingUserTimeoutIds: {},
|
363 | 369 | throttledEmitUserTypingEvent: throttle(this.emitUserTypingEvent, 500),
|
@@ -565,18 +571,6 @@ export default ({
|
565 | 571 | handlePaste (e) {
|
566 | 572 | if (e.clipboardData.files.length > 0) {
|
567 | 573 | 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() |
580 | 574 | }
|
581 | 575 | },
|
582 | 576 | addSelectedMention (index) {
|
@@ -630,7 +624,7 @@ export default ({
|
630 | 624 | return true
|
631 | 625 | },
|
632 | 626 | updateTextArea () {
|
633 |
| - if (!this.updateTextWithLines()) { |
| 627 | + if (!this.$refs.textarea || !this.updateTextWithLines()) { |
634 | 628 | // dont calculate again when the value is the same (ex: happens on shift+enter)
|
635 | 629 | return false
|
636 | 630 | }
|
|
0 commit comments