Closed izarutskaya closed 1 week ago
Not overdue, still open for proposals!
Edited by proposal-police: This proposal was edited at 2024-09-11 07:51:41 UTC.
Reproduction step:
https://github.com/user-attachments/assets/e915e32c-affb-482a-addc-46e14598b93f
The new RN live markdown implements a new scrollIntoView function. This implementation will scroll element (which could be <span>
, <p>
,... that contains the cursor into view. However, this won't work in case the text inside <span>
element is long enough to cover the bound height of the input (check the image below)
And in this case, only the beginning of the paragraph (the span
element) is scrolled into view, but not the cursor.
We can bring this implementation from 0.1.116
.
function scrollIntoView(target: MarkdownTextInputElement, node: TreeNode) {
if (node.type === 'br' && node.parentNode?.parentNode?.type === 'line') {
// If the node is a line break, scroll to the parent paragraph, because Safari doesn't support scrollIntoView on br elements
node.parentNode.parentNode.element.scrollIntoView({
block: 'nearest',
});
} else {
// brought the old implementation here
if (BrowserUtils.isFirefox) {
// In the old implementation we don't support scroll the cursor into view in Firefox, so in here we can simply call `scrollIntoView` (which is the new implementation)
node.element.scrollIntoView({
block: 'nearest',
});
return;
}
// old implementation: Calculate the cursor position and force the input to scroll to the exact coordinates
const selection = window.getSelection();
if (!selection || selection.rangeCount === 0) {
return;
}
const caretRects = selection.getRangeAt(0).getClientRects();
// we'll find the caretRect from the DOMRectList above with the largest bottom value
let currentCaretRect = caretRects[0];
if (currentCaretRect) {
for (let i = 1; i < caretRects.length; i++) {
const caretRect = caretRects[i];
if (caretRect && caretRect.bottom > currentCaretRect.bottom) {
currentCaretRect = caretRect;
}
}
}
const editableRect = target.getBoundingClientRect();
// Adjust for padding and border
const paddingTop = parseFloat(window.getComputedStyle(target).paddingTop);
const borderTop = parseFloat(window.getComputedStyle(target).borderTopWidth);
if (currentCaretRect && !(currentCaretRect.top >= editableRect.top + paddingTop + borderTop && currentCaretRect.bottom <= editableRect.bottom - 2 * (paddingTop - borderTop))) {
const topToCaret = currentCaretRect.top - editableRect.top;
const inputHeight = editableRect.height;
// Chrome Rects don't include padding & border, so we're adding them manually
const inputOffset = currentCaretRect.height - inputHeight + paddingTop + borderTop + (BrowserUtils.isChromium ? 0 : 4 * (paddingTop + borderTop));
target.scrollTo(0, topToCaret + target.scrollTop + inputOffset);
}
}
}
@mollfpr , plz review @dominictb 's proposal above, thx
Issue not reproducible during KI retests. (First week)
@mallenexpensify, @mollfpr Whoops! This issue is 2 days overdue. Let's get this updated quick!
@mollfpr and @dominictb , regarding the post from QA not being able to reproduce, can you both attempt reproduction and share your results? If you're able to, please provide vid or screenshots.
I am still able to reproduce the issue, it's only reproducible with long text paragraphs and doesn't have a break-line space at the end of the paragraph. The same things happen for Safari.
https://github.com/user-attachments/assets/fb21d21f-a34d-4060-a392-7f744321ce36
@dominictb Is there a reason we using scrollIntoView
from the element interface and replacing our own logic?
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸
Triggered auto assignment to @joekaufmanexpensify (Bug
), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.
@joekaufmanexpensify I'm out til Tuesday, can you keep 👀 on plz? Thx
https://github.com/Expensify/App/issues/45885#issuecomment-2343744710
@mollfpr I don't have the answer for that, my guess is because they miss the test case when they try to refactor the markdown library.
@BartoszGrajdek @Skalakid loop in you guys for second opinion.
@dominictb I'm not sure if bringing back the old solution is a good idea. One of the goals of our refactor was to get rid of scrolling into view by calculating pixels. We wanted to simplify it and use the new structure elements as a base for a new approach. We've missed the case when the element's content is too long, but we can definitely fix this issue by modifying the current solution. My idea is to detect if the cursor is outside the view and just launch node.element.scrollIntoView(false)
or node. element.scrollIntoView({block: "bottom"})
to scroll to it
@Skalakid your idea doesn't work in this test case:
-> Now it scrolls down to the bottom due to the fact that the startTreeNode
is now a large <span>
, but the cursor appears in the middle (and out of view).
https://github.com/user-attachments/assets/37641b77-1ac1-4c7e-9f3d-aeb01025163d
Issue not reproducible during KI retests. (Second week)
I'm not sure if bringing back the old solution is a good idea. One of the goals of our refactor was to get rid of scrolling into view by calculating pixels. We wanted to simplify it and use the new structure elements as a base for a new approach. We've missed the case when the element's content is too long, but we can definitely fix this issue by modifying the current solution.
I agree with @Skalakid 👍
@dominictb Let's try to find a solution that fits the current implementation.
Going to try reproducing this today, as it sounds like it may no longer be reproducible?
@joekaufmanexpensify this is reproducible as mentioned above.
Let's try to find a solution that fits the current implementation.
@mollfpr this is tricky. I'll need to do some testing and get back on this later.
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸
Hello, I decided to investigate this issue more inside the library since I have more capacity. To fix this issue and overall scrolling into view logic, we have to make some bigger logic changes inside the library.
First of all, we don't need to scrollIntoView on every input change or event. We can do it only on the actions that were totally replaced by our custom implementation, like: onPaste
and onFocus
and value
prop changes. The rest of the actions can use the default browser's scroll logic. Thanks to that, Live Markdown Input works and feels more like normal RN TextInput.
After that, we can update our scrollIntoView
function, so whenever the cursor isn't visible inside the input window, it scrolls to the position of the cursor range. Something like this:
const selection = window.getSelection();
if (selection && selection.rangeCount > 0) {
const range = selection.getRangeAt(0);
const caretRect = range.getBoundingClientRect();
const targetRect = target.getBoundingClientRect();
// In case the caret is below the visible input area, scroll to the cursor position
if (caretRect.top + caretRect.height > targetRect.top + targetRect.height) {
targetElement.scrollTop = caretRect.top + caretRect.height - targetRect.top - targetRect.height + target.scrollTop;
}
}
I will come back to you with the PR today
Here is the PR with the fix inside the react-native-live-markdown
library: https://github.com/Expensify/react-native-live-markdown/pull/502
@mallenexpensify, @mollfpr Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
Issue not reproducible during KI retests. (Third week)
@mallenexpensify, @mollfpr 6 days overdue. This is scarier than being forced to listen to Vogon poetry!
@Skalakid is working on so I add them as an assignee
@mallenexpensify, @mollfpr, @Skalakid 8 days overdue is a lot. Should this be a Weekly issue? If so, feel free to change it!
Hello, the PR with the bump was reverted. Here I'm bumping the library again
@mallenexpensify, @mollfpr, @Skalakid 8 days overdue is a lot. Should this be a Weekly issue? If so, feel free to change it!
Issue not reproducible during KI retests. (Fourth week)
@mallenexpensify, @mollfpr, @Skalakid 12 days overdue now... This issue's end is nigh!
This issue has not been updated in over 14 days. @mallenexpensify, @mollfpr, @Skalakid eroding to Weekly issue.
@Skalakid can you provide an update? Wondering if this is worth fixing, def an edge case bug that's not going to affect many/anyone.
Hello, the PR with the fix has been merged so the issue should be fixed now
@mallenexpensify I can't repro the issue anymore. I think we can close this.
Thanks @mollfpr , closing. Comment/reopen if anyone disagrees.
If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!
Version Number: 9.0.10 Reproducible in staging?: Y Reproducible in production?: Y Logs: https://stackoverflow.com/c/expensify/questions/4856 Issue reported by: Applause-Internal team
Action Performed:
Expected Result:
Pasting long text in description must scrolled to bottom & cursor must be shown at end.
Actual Result:
Pasting long text in description not scrolled to bottom & cursor is shown in middle of text instead of end.
This happens in task description and in other description field across the app.
Workaround:
Unknown
Platforms:
Which of our officially supported platforms is this issue occurring on?
Screenshots/Videos
https://github.com/user-attachments/assets/5a995426-49ea-4adc-ae42-a15bccdc1c97
View all open jobs on GitHub
Upwork Automation - Do Not Edit
Issue Owner
Current Issue Owner: @mollfpr