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

Add selectionStart and selectionEnd variables to markdown input ref #176

Merged
merged 4 commits into from
Feb 14, 2024

Conversation

Skalakid
Copy link
Collaborator

@Skalakid Skalakid commented Feb 9, 2024

Details

This PR fixes how our markdown text input tracks text selection and adds selectionStart and selectionEnd variables to input ref.

Related Issues

#173

Manual Tests

Using reproduction code from the linked issue start changing the text selection. Verify in console if it returns correct values. Next, position your cursor at the beginning of the markdown text input and after clicking arrow up, verify if focus is changed into RN text input that is above

Linked PRs

Expensify/App#36173

@Skalakid Skalakid requested review from tomekzaw and robertKozik and removed request for tomekzaw February 9, 2024 11:47
robertKozik
robertKozik previously approved these changes Feb 9, 2024
Comment on lines 176 to 177
(divRef.current as HTMLInputElement).selectionStart = selection.start;
(divRef.current as HTMLInputElement).selectionEnd = selection.end;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's assign divRef.current to a new variable

markdownHTMLInput.selectionStart = selection.start;
markdownHTMLInput.selectionEnd = selection.end;
contentSelection.current = selection;
return selection;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return selection;

Comment on lines 360 to 363
const handleKeyUp = useCallback(() => {
updateSelection();
}, []);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const handleKeyUp = useCallback(() => {
updateSelection();
}, []);

Comment on lines 368 to 369
const selection = updateSelection();
if (onSelectionChange && selection) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const selection = updateSelection();
if (onSelectionChange && selection) {
updateSelection();
if (onSelectionChange && contentSelection.current) {

@@ -488,6 +499,7 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
autoCapitalize={autoCapitalize}
className={className}
onKeyDown={handleKeyPress}
onKeyUp={handleKeyUp}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
onKeyUp={handleKeyUp}
onKeyUp={updateSelection}

Copy link
Collaborator

@tomekzaw tomekzaw left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this!

@Skalakid Skalakid merged commit 575d6fd into main Feb 14, 2024
2 checks passed
@Skalakid Skalakid deleted the @Skalakid/selection-variables-inside-input-ref branch February 14, 2024 14:42
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.

3 participants