Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2369 chat paste bug #2370

Merged
merged 5 commits into from
Oct 7, 2024
Merged

#2369 chat paste bug #2370

merged 5 commits into from
Oct 7, 2024

Conversation

SebinSong
Copy link
Collaborator

closes #2369

The textarea element needed a 'paste' event handler.

@SebinSong SebinSong self-assigned this Oct 4, 2024
Copy link

cypress bot commented Oct 4, 2024

group-income    Run #3221

Run Properties:  status check passed Passed #3221  •  git commit 23b81cac9f ℹ️: Merge 52ad0c44789756887af679636c48dea6b3b358c0 into a8cbe02389bc3f56d5c566574d42...
Project group-income
Branch Review sebin/task/#2369-chat-paste-bug
Run status status check passed Passed #3221
Run duration 09m 31s
Commit git commit 23b81cac9f ℹ️: Merge 52ad0c44789756887af679636c48dea6b3b358c0 into a8cbe02389bc3f56d5c566574d42...
Committer Sebin Song
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 10
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 111
View all changes introduced in this branch ↗︎

@corrideat
Copy link
Member

This works! However, I wonder if using the input event might be a more generic approach. This seems to work for me: @input='()=>this.updateTextArea()'.

@SebinSong
Copy link
Collaborator Author

@corrideat
If you look more closely in SendArea.vue, capturing what user has typed are all done via either calling this.$refs.textarea.value or through keydown event handler (which is already calling this.updateTextarea). so your solution will lead to calling it twice unnecessarily.

(Don't know if you write Vue code too but) It's more typical/generic approach to use v-model (which inherently uses input event) in a vue component.

But I'm sure the front-end author(s) of this component didn't use neither of them for a reason:
SendArea.vue currently has various UI/UX related logics triggered by user typing action (eg. auto-sizing the textarea element height if the content is multiple lines etc..) and they decided that using keydown event is more suitable to account for all of them.

So, adding input event handler is not only duplicate but also will very likely lead to creating conflicts with these existing logics. dismissing the review.

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @SebinSong! There's a critical bug here:

@@ -553,6 +554,11 @@ export default ({
this.updateMentionKeyword()
}
},
handlePaste (e) {
const pastedText = e.clipboardData.getData('text')
this.$refs.textarea.value = pastedText
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will replace all existing text with the pasted text, overwriting the value.

Instead of that, we want the pasted value to be inserted where the cursor is like normal.

Copy link
Member

@corrideat corrideat Oct 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion of using the input event doesn't need this handlePaste handler (it needs a much simpler handler, as shown in my example). However, I didn't thoroughly test it.

and they decided that using keydown event is more suitable to account for all of them.

I did see the duplicate logic for triggering the update (actually, it could possibly be duplicate, if you paste without using keys it won't be a duplicate), however it doesn't seem like a big issue considering that it's not expensive to call it.

As for conflicts, I didn't really see anything that would conflict.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not make sense to add input when there is keyodwn already in place. It has to be either one of them. They are two events that look similar but behave differently in certain cases in my experience. For that reason it's a type of change I would be very cautious to do at this point (Considering this code has been this way for a long while). Also, as I said above, I think other front-end devs chose to use keydown instead of input for a reason.

@SebinSong
Copy link
Collaborator Author

@taoeffect Updated the fix again!

frontend/main.js Outdated Show resolved Hide resolved
taoeffect
taoeffect previously approved these changes Oct 6, 2024
Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @SebinSong! 👏

@taoeffect taoeffect merged commit b64ecda into master Oct 7, 2024
4 checks passed
@taoeffect taoeffect deleted the sebin/task/#2369-chat-paste-bug branch October 7, 2024 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Send button remains disabled when pasting text in chat on mobile
3 participants