fix point transform for insert_text to account for affinity #4848
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When one creates a RangeRef with affinity
outward
and the ref becomes collapsed, it can't be expanded again with aninsert_text
operation (although it should IMO).Example
Lets take an example string (and not care about paths for simplicity sake)
The RangeRef is the following
Now if the user types something at offset 4 (right after the first word) the RangeRef right now changes to the following
Although I naively expected it to be this.
Context
If you take a collapsed RangeRef with affinity
outward
and apply aninsert_text
operation at the offset of where the Range is the following happens:Because the collapsed ranges count as forward pointing ranges, the
Range.transform()
will determine the anchors' affinity asbackward
. Therefor it will run thePoint.transform()
on the anchor with that affinity. But, because thePoint.transform()
doesn't account for the affinity, the offset of the anchor gets incremented regardless. The same happens with the focus thus the Range will stay collapsed.Checks
yarn test
.yarn lint
. (Fix errors withyarn fix
.)yarn start
.)yarn changeset add
.)