-
Notifications
You must be signed in to change notification settings - Fork 71
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
Add selectionStart and selectionEnd variables to markdown input ref #176
Conversation
src/MarkdownTextInput.web.tsx
Outdated
(divRef.current as HTMLInputElement).selectionStart = selection.start; | ||
(divRef.current as HTMLInputElement).selectionEnd = selection.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.
Let's assign divRef.current
to a new variable
src/MarkdownTextInput.web.tsx
Outdated
markdownHTMLInput.selectionStart = selection.start; | ||
markdownHTMLInput.selectionEnd = selection.end; | ||
contentSelection.current = selection; | ||
return selection; |
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.
return selection; |
src/MarkdownTextInput.web.tsx
Outdated
const handleKeyUp = useCallback(() => { | ||
updateSelection(); | ||
}, []); | ||
|
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 handleKeyUp = useCallback(() => { | |
updateSelection(); | |
}, []); |
src/MarkdownTextInput.web.tsx
Outdated
const selection = updateSelection(); | ||
if (onSelectionChange && selection) { |
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 selection = updateSelection(); | |
if (onSelectionChange && selection) { | |
updateSelection(); | |
if (onSelectionChange && contentSelection.current) { |
src/MarkdownTextInput.web.tsx
Outdated
@@ -488,6 +499,7 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>( | |||
autoCapitalize={autoCapitalize} | |||
className={className} | |||
onKeyDown={handleKeyPress} | |||
onKeyUp={handleKeyUp} |
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.
onKeyUp={handleKeyUp} | |
onKeyUp={updateSelection} |
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.
Thanks for fixing this!
Details
This PR fixes how our markdown text input tracks text selection and adds
selectionStart
andselectionEnd
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 aboveLinked PRs
Expensify/App#36173