-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[HOLD for payment 2023-09-06] [$1000] Pasting on Web isn't automatically focusing on composer #25550
Comments
Triggered auto assignment to @NicMendonca ( |
Bug0 Triage Checklist (Main S/O)
|
ProposalPlease re-state the problem that we are trying to solve in this issue.When a user tries to paste content into the chat composer without it being focused, the expected behavior is that the composer should automatically gain focus and the content should be pasted. However, currently, nothing happens. What is the root cause of that problem?There isn't any global event listener that listens for the paste event (CMD+V/CTRL+V) when the composer is unfocused. This means that when the composer is not in focus and the user tries to paste content, there's no mechanism in place to detect this action and subsequently focus the composer and paste the content. What changes do you think we should make in order to solve the problem?To address this issue, we need to add a global event listener that listens for the paste event, focuses the composer when it's triggered, and pastes the content into the composer. Here's a step-by-step solution using React hooks:
Here's a code snippet that demonstrates the proposed changes in ReportActionCompose.js file: useEffect(() => {
const handlePaste = (e) => {
// Check if the composer is focused
if (textInputRef.current && !textInputRef.current.isFocused()) {
// Focus the composer
textInputRef.current.focus();
// Allow some time for the focus event to complete before pasting the content
setTimeout(() => {
// Trigger a paste event on the composer
if (textInputRef.current) {
textInputRef.current.value = e.clipboardData.getData('text');
}
}, 0);
}
};
// Add global event listener for paste event
document.addEventListener('paste', handlePaste);
// Cleanup: Remove the global event listener when the component is unmounted
return () => {
document.removeEventListener('paste', handlePaste);
};
}, []); Result: 2023-08-20.19-49-34.mp4What alternative solutions did you explore? (Optional) |
ProposalPlease re-state the problem that we are trying to solve in this issue.Pasting on Web isn't automatically focusing on composer What is the root cause of that problem?we already have the logic to handle paste event, but we are preventing paste if the target is not textInput In App/src/components/Composer/index.js Lines 275 to 277 in 03cf0b1
That is not correct, because when the input is blurred, then users paste text, the What changes do you think we should make in order to solve the problem?we can remove these lines App/src/components/Composer/index.js Lines 275 to 277 in 03cf0b1
Then focus into the compose before executing Change App/src/components/Composer/index.js Lines 224 to 225 in 03cf0b1
to
ResultScreen.Recording.2023-08-21.at.14.59.14.mov |
ProposalPlease re-state the problem that we are trying to solve in this issue.Pasting text using Ctrl + v, will not focus the composer What is the root cause of that problem?Right now, we're handling key presses to make the composer focused and input the key. However, we're not yet managing the onKeyPress function to both focus the composer and input text when using the shortcut Ctrl + v/CMD + v. What changes do you think we should make in order to solve the problem?We should focus the input if the key is App/src/pages/home/report/ReportActionCompose.js Lines 459 to 465 in 03cf0b1
\We'll include a check with a condition: if(e.metaKey && e.nativeEvent.code === 'KeyV' && !['INPUT', 'TEXTAREA'].includes(e.target.nodeName)) {
focus();
return;
} Screen.Recording.2023-08-21.at.10.55.55.AM.movWhat alternative solutions did you explore? (Optional) |
Job added to Upwork: https://www.upwork.com/jobs/~01ed32306975a2bc2a |
Current assignee @NicMendonca is eligible for the External assigner, not assigning anyone new. |
Triggered auto assignment to Contributor-plus team member for initial proposal review - @s77rt ( |
I think this intended, we've stopped it. #25409 (comment) |
@NicMendonca So do we want to enable it now? |
@rayane-djouah Thanks for the proposal. Your RCA is not exactly right, we do have a global listener for paste events even if the composer is not focused (as long as its screen is focused). However we just return early and do nothing in this case.. Please note that the use of |
@tienifr Thanks for the proposal. Your RCA is correct. However your proposed solution is outdated. Please update it to reflect the current |
@getusha Thanks for the proposal. Your RCA makes sense. However the solution does not seem to be working. I think the proposal is outdated. Please update it and tag me again.. |
ProposalPlease re-state the problem that we are trying to solve in this issue.When the composer isn't focused, paste events are not handled by the composer. This means that no text is pasted into the composer/the composer is not focused. What is the root cause of that problem?There is an early return that stops paste event handling if the composer was not the target of the paste event. App/src/components/Composer/index.js Lines 275 to 277 in 8f772ea
What changes do you think we should make in order to solve the problem?I think we should modify the aforementioned early return: App/src/components/Composer/index.js Lines 275 to 277 in 8f772ea
We only need to return if another text input was the target element of the paste. Otherwise we can focus the composer, and let the regular paste handling proceed:
This works for both pasting via the context menu: Screen.Recording.2023-08-22.at.02.24.59.movAnd via keyboard shortcuts: Screen.Recording.2023-08-22.at.02.25.59.movCrucially this approach won't reintroduce other pasting bugs: 720Screen.Recording.2023-08-22.at.11.14.50.movFor example it will not reintroduce the bug of not being able to paste into the emoji picker: Screen.Recording.2023-08-22.at.11.26.24.movEdit: we might also want to add a prop to the composer, called something like
What alternative solutions did you explore? (Optional) |
ProposalPlease re-state the problem that we are trying to solve in this issue.Pasting on Web isn't automatically focusing on composer What is the root cause of that problem?We're manually blocking the paste events if the input is focused. Also we're blocking the any meta related events to trigger the focus here
What changes do you think we should make in order to solve the problem?Here we're checking for App/src/components/Composer/index.js Line 268 in d09faa6
We can update the function to focus if it the event is paste event which we can trigger by using the event from variable from here App/src/components/Composer/index.js Lines 266 to 268 in d09faa6
Changesconst isVisible = checkComposerVisibility(event); // Focus the composer if it is not focused or it's not coming from paste event (e can be empty) && check for the paste event details
if (!textInputRef.current.isFocused() && !_.isEmpty(e) && (e.metaKey || e.ctrlKey) && e.key === 'v') {
focus();
return true;
}
This won't break any previous issues like
What alternative solutions did you explore? (Optional)NA ResultKapture.2023-08-22.at.10.41.01.mp4 |
@s77rt Sorry if I miss something, Why is my proposal outdated?
It works well in this case too. |
Updated my proposal by adding two videos showing that it will not break existing paste functionality |
@getusha Thanks for the update. Unfortunately the solution does not seem to be working for me. The composer gets focused but the text is not pasted. Can you please double check? (and test on Kooha-2023-08-22-22-30-35.webm |
@tienifr Sorry, my bad here. Your proposal is not outdated, I just misread the function callback ( Kooha-2023-08-22-22-32-41.webm |
📣 @joh42 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app! Offer link |
📣 @PauloGasparSv! 📣
|
The BZ member will need to manually hire PauloGasparSv for the Reporter role. Please store your Upwork details and apply to our Upwork job so this process is automatic in the future! |
Thanks! You can expect a PR later today. |
Raised a bug here about the regression this would be causing. https://expensify.slack.com/archives/C049HHMV9SM/p1692987504856949 @s77rt |
@b4s36t4 It does not seem to be a regression from this PR. I can reproduce even with the PR reverted. Screen.Recording.2023-08-25.at.7.36.11.PM.mov |
|
The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.58-5 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue: If no regressions arise, payment will be issued on 2023-09-06. 🎊 After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.
For reference, here are some details about the assignees on this issue:
As a reminder, here are the bonuses/penalties that should be applied for any External issue:
|
BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:
|
Regression Test Proposal (Web/Desktop Only)
|
@joh42 you've been paid! 🎉 |
@s77rt can you remind me, are you paid via Expensify or Upwork? |
all set here ✅ |
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Action Performed:
CMD+C
/CTRL+C
)CMD+V
/CTRL+V
)Expected Result:
The composer should be focused and the text should be pasted into it.
Actual Result:
Nothing happens
Workaround:
Can the user still use Expensify without this being fixed? Have you informed them of the workaround?
Platforms:
Which of our officially supported platforms is this issue occurring on?
Version Number: 1.3.55-2
Reproducible in staging?: y
Reproducible in production?: y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation
Recording.5943.mp4
Expensify/Expensify Issue URL:
Issue reported by: @PauloGasparSv
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1691623314942259
View all open jobs on GitHub
Upwork Automation - Do Not Edit
The text was updated successfully, but these errors were encountered: