-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Web - Composer - Cursor positioned at the start if pasting text which contains a new line #42892
base: main
Are you sure you want to change the base?
Conversation
@eVoloshchak Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
src/hooks/useHtmlPaste/index.ts
Outdated
@@ -16,8 +16,9 @@ const insertAtCaret = (target: HTMLElement, text: string) => { | |||
range.insertNode(node); | |||
|
|||
// Move caret to the end of the newly inserted text node. | |||
range.setStart(node, node.length); | |||
range.setEnd(node, node.length); | |||
const offset = (text.length && text[text.length - 1] === '\n' ? node.length - 1 : node.length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const offset = (text.length && text[text.length - 1] === '\n' ? node.length - 1 : node.length); | |
const offset = text?.endsWith('\n') ? node.length - 1 : node.length; |
src/hooks/useHtmlPaste/index.ts
Outdated
@@ -16,8 +16,9 @@ const insertAtCaret = (target: HTMLElement, text: string) => { | |||
range.insertNode(node); | |||
|
|||
// Move caret to the end of the newly inserted text node. | |||
range.setStart(node, node.length); | |||
range.setEnd(node, node.length); | |||
const offset = (text.length && text[text.length - 1] === '\n' ? node.length - 1 : node.length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment explaining why this logic is needed and include a link to the issue?
Hi, @eVoloshchak |
src/hooks/useHtmlPaste/index.ts
Outdated
@@ -16,8 +16,12 @@ const insertAtCaret = (target: HTMLElement, text: string) => { | |||
range.insertNode(node); | |||
|
|||
// Move caret to the end of the newly inserted text node. | |||
range.setStart(node, node.length); | |||
range.setEnd(node, node.length); | |||
// we have to set offset as `node.length - 1` when text has empty line at the end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// we have to set offset as `node.length - 1` when text has empty line at the end | |
// Correctly calculate text length since newline character does not create a new line in HTML | |
// https://github.com/Expensify/App/issues/42216 |
@moonstar-95515, looks awesome, there are a couple of steps left to finish up the author checklist:
|
@eVoloshchak |
@moonstar-95515, works fine for me (a little slow though) |
@eVoloshchak |
@moonstar-95515, try doing this Screen.Recording.2024-06-10.at.19.01.27.mov |
@eVoloshchak |
@moonstar-95515, did you pull the latest changes from main? |
@eVoloshchak |
@moonstar-95515, could you push this commit so I can test this PR with the latest changes? |
@eVoloshchak |
It is much preferred if we both double-check all of the platforms, let's try to get this working on Android for you. What problem are you having? |
Thank you I got it. |
@moonstar-95515, check out our TESTING_MACOS_AND_IOS.md guide |
I was working on this issue initially. When my PR was in progress, proposal for this PR was picked up. Based on @jayeshmangwani comment, ideally this PR and proposal should have been withdrawn. My PR is on HOLD for quite some days now. However, as @moonstar-95515 also suggested a good alternative solution for the issue, but now that they are stuck with continuing, I am ok with taking this forward in whichever way Expensify sees it logical as per code of conduct. @jayeshmangwani / @roryabraham / @eVoloshchak / @slafortune / @mallenexpensify : kindly suggest way forward. |
I'm sorry that I have some issues with recording test video but I'm still working on this issue. @kpadmanabhan |
@moonstar-95515 : thanks for the update. Will await completion of your PR. |
@moonstar-95515, were you able to get your development environment working? |
@eVoloshchak |
@moonstar-95515, it is possible Could you share which problems you're having exactly? |
Thank you. @eVoloshchak |
@moonstar-95515 What error did you encounter? |
@moonstar-95515 per CONTRIBUTING.md, it's a requirement to be able to test on Android
This PR has been open for over a month, I'd love to get it wrapped ASAP |
Thank you everybody. @eVoloshchak |
@moonstar-95515, looks like this is already resolved on staging, could you double-check please? Screen.Recording.2024-07-08.at.00.06.04.mov |
Also confirming I am unable to reproduce on staging.new.expensify.com . Anyone know what PR might have fixed this? |
@eVoloshchak @mallenexpensify I tested this today, and the issue is happening again, even though it was working fine two days ago. It is working fine in production, but the issue is happening on staging |
I'm experiencing a different bug on staging (and not production), when I paste text with a blank line underneath, it shows being greyed out and I'm not able to type 'return' to send the message 2024-07-11_17-28-34.mp4 |
I tested on main HEAD without applying any local fixes. the core problem is fixed. @jayeshmangwani, the approach taken here is to trim off the trailing new-line. This was my first proposal, which is on hold for almost 2 months now. But these changes from someone else has reached production bypassing all regressions. Referring to this. @eVoloshchak : code in main HEAD trims off newlines from inside code block irrespective of how much ever you copy. refererring to this. @mallenexpensify : due to extra long waiting times with issues on HOLD, I see that others are fixing code in the same area and the same is merged to main with known regressions (due to which my PR was put on hold). Kin dly suggest how to proceed here. |
@kpadmanabhan commented on the issue you're assigned, can you follow up there plz? thx |
@moonstar-95515, since the issue was already resolved, could you close this PR please? |
Details
Web - Composer - Cursor positioned at the start if pasting text which contains a new line
Fixed Issues
$ #42216
PROPOSAL: #42216 (comment)
Tests
Verify the cursor is positioned at the end of the pasted text
Offline tests
QA Steps
Verify the cursor is positioned at the end of the pasted text
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
android.mp4
Android: mWeb Chrome
android.-chrome.mp4
iOS: Native
ios-native.mp4
iOS: mWeb Safari
bandicam.2024-06-11.17-34-50-999.mp4
MacOS: Chrome / Safari
web.mp4
MacOS: Desktop
bandicam.2024-06-11.17-03-26-854.mp4