-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Resolve Cursor Position Issue on Long-Press in Android Chrome #30082
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,10 +136,19 @@ function MoneyRequestAmountForm({amount, currency, isEditing, forwardedRef, onCu | |
if (!_.isEmpty(formError)) { | ||
setFormError(''); | ||
} | ||
|
||
// There was an issue where long-pressing the back button in Android Chrome removed the last digit but moved the cursor ahead two positions instead of one. This occurred because setCurrentAmount contains another setState, making it impure and error-prone. Various solutions were suggested, including merging currentAmount and selection; however, this solution introducing the hasSelectionBeenSet flag was chosen for its simplicity and lower risk of future errors https://github.com/Expensify/App/issues/23300. | ||
|
||
let hasSelectionBeenSet = false; | ||
setCurrentAmount((prevAmount) => { | ||
const strippedAmount = MoneyRequestUtils.stripCommaFromAmount(newAmountWithoutSpaces); | ||
const isForwardDelete = prevAmount.length > strippedAmount.length && forwardDeletePressedRef.current; | ||
setSelection((prevSelection) => getNewSelection(prevSelection, isForwardDelete ? strippedAmount.length : prevAmount.length, strippedAmount.length)); | ||
if (!hasSelectionBeenSet) { | ||
setSelection((prevSelection) => { | ||
hasSelectionBeenSet = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason to set it inside the setSelection, wouldn't having it after the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that makes more sense. That's what I had intially tried but saw some issues. I don't see those now, so i have moved the |
||
return getNewSelection(prevSelection, isForwardDelete ? strippedAmount.length : prevAmount.length, strippedAmount.length); | ||
}); | ||
} | ||
return strippedAmount; | ||
}); | ||
}, | ||
|
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.
This is super long. Can we make it short and crisp and link the GH comment..