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

Use old approach to update selection's 2D positions #581

Merged
merged 2 commits into from
Sep 11, 2017
Merged

Use old approach to update selection's 2D positions #581

merged 2 commits into from
Sep 11, 2017

Conversation

JordanMartinez
Copy link
Contributor

@JordanMartinez JordanMartinez commented Sep 10, 2017

Resolves #579

@JordanMartinez JordanMartinez changed the title Add test: UI-initiated all-text deletion should not throw exception Use old approach to update selection's 2D positions Sep 10, 2017
For some reason, updating these positions using `Val.create(supplier, internalRange.invalidations)` (alternative current/new approach) does not work. It seems that `Val` handles invalidation slightly differently
@JordanMartinez
Copy link
Contributor Author

The approach I was using before this PR throws an exception:

// Approach #1
Val<Position> start2DPosition = Val.create(() -> {
    IndexRange sel = internalRange.getValue();
    return area.offsetToPosition(sel.getStart(), Forward);
    },
        internalRange.invalidations()
);
Val<Position> end2DPosition = start2DPosition.map(pos2D -> getLength() == 0 ? pos2D : pos2D.offsetBy(getLength(), Backward));

but the original approach that was used before things were extracted doesn't throw that exception:

// Approach #2
internalRange.addListener(obs -> {
    IndexRange sel = internalRange.getValue();
    start2DPosition.setValue(area.offsetToPosition(sel.getStart(), Forward));
});
Val<Position> end2DPosition = start2DPosition.map(pos2D -> getLength() == 0 ? pos2D : pos2D.offsetBy(getLength(), Backward));

I used Approach 1 because I thought it cleaned up the code better than 2. In this PR, I'm following A2 but with a few things cleaned up.

@JordanMartinez JordanMartinez merged commit cce2fc2 into FXMisc:master Sep 11, 2017
@JordanMartinez JordanMartinez deleted the fixSelectAllBug branch September 11, 2017 15:55
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.

1 participant