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

don't allow setSelection on invalid range #835

Closed
wants to merge 5 commits into from
Closed

Conversation

mzorz
Copy link
Contributor

@mzorz mzorz commented Apr 5, 2019

Fixes the third case reported in this comment here: #208 (comment)

As expressed elsewhere, while the root cause of it may lay on how undo/redo and lists changes are working together, the extra check here should be harmless and fixes the issue for the time being.

@mzorz mzorz added this to the v1.2 milestone Apr 5, 2019
@mzorz mzorz requested review from hypest and jtreanor April 5, 2019 15:19
@@ -194,7 +194,9 @@ private void updateSelectionIfNeeded(ReactAztecText view, @Nullable ReadableMap
if ( selection != null ) {
int start = selection.getInt("start");
int end = selection.getInt("end");
view.setSelection(start, end);
if (view.getText().length() > end && start >= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can add the equality to end in the condition since the caret can actually be placed right after the last char.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, let's add a line comment about why we're doing this here, wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

both addressed in 7b8955a

@mzorz mzorz changed the base branch from release/1.2 to develop April 5, 2019 16:12
@peril-wordpress-mobile
Copy link

Warnings
⚠️ PR has more than 500 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS

@mzorz
Copy link
Contributor Author

mzorz commented Apr 5, 2019

Just changed the base branch as we won't be merging it into release/12.1- we have some concerns about sync state between the native / JS side of things. We’ll continue looking into it.

@hypest
Copy link
Contributor

hypest commented Apr 17, 2019

FWIW, the ticket this PR was trying to address (#836) is closed now as it's not happening anymore so, we could concider closing this PR.

Though, the fix here is one that we might still consider doing if we end up not fixing the root causes of how come the RN side tries to set the selection to a position that is beyond the text length. Context: #871 (comment)

@mzorz
Copy link
Contributor Author

mzorz commented Apr 17, 2019

I think while the check looks harmless it could hide other problems so if the most urgent problem is not happening anymore I'd lean more to closing this one - also the references to this PR will still be there in case we need to grab n go with them in case we decide to not pursue the root cause further 👍

@mzorz mzorz closed this Apr 17, 2019
@mzorz mzorz deleted the fix/crash-undo-list branch April 17, 2019 12:05
@hypest
Copy link
Contributor

hypest commented Apr 17, 2019

it could hide other problems

That's exactly what I'm struggling with at the moment 😬. This workaround works but masks all errors that stem from the RN side getting out-of-sync with Aztec. It will hide problems that we might miss or make hard to debug.

Looping back, I've taken a slightly different route with WordPress/gutenberg#15021. Instead of letting Aztec accept the out-of-bounds selection range, I'm checking in the RN side when the html will get trimmed and avoid trying to set the caret in that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants