Repository navigation
Input Interaction: restore collapsing selection before edge calc - #14906
Conversation
|
Hm, I ran the e2e test against |
4d7e88b to
5d668f3
Compare
|
Fixed. Looks like it needed minimum three characters per line. |
|
I'm not sure why this code change makes 6fa60b2 needed, but this seems the correct behaviour to me now. |
|
The fixed test was introduced in caaf204, which also introduced the code that was removed. But again, the fixed test in this PR seems like the correct behaviour to me. Twice arrow up from a certain horizontal position should land the caret in the same horizontal position if possible. |
|
I think the reason is that the range is now cloned, before handing it to
gutenberg/packages/dom/src/dom.js Lines 205 to 215 in 0bc9067 |
Yes, I compared the results of the test steps on |
aduth
left a comment
There was a problem hiding this comment.
Makes sense, tests well.
Not so sure about where cloneRange in getRectangleFromRange is necessary, but I don't think it can hurt anyways. I'll leave it to your discretion on my feedback.
| if ( ! rect ) { | ||
| const padNode = document.createTextNode( '\u200b' ); | ||
| // Do not modify to live range. | ||
| range = range.cloneRange(); |
There was a problem hiding this comment.
It reminds me of some unrelated testing I'd been doing with Chrome line-ending bugginess, where Range#cloneRange wasn't actually avoiding mutations to the original:
https://codepen.io/aduth/pen/WPjQoW
(See comment: "// WIP: Buggy, collapses spaces (mutates original).")
I never did figure out what I was seeing with my demos. I raise only in case there's still a worry about mutating the cloned value.
There was a problem hiding this comment.
I've not tested the Codepen, but when you make this change in master, this test will also fail:
gutenberg/packages/e2e-tests/specs/adding-blocks.test.js
Lines 64 to 71 in 917338c
It is true that cloning the range in isEdge will also prevent this issue, but I think it is safe to clone here is well in case it is called with a live range.
In my testing insertNode doesn't modify the original range.
| // See: https://stackoverflow.com/a/6847328/995445 | ||
| if ( ! rect ) { | ||
| const padNode = document.createTextNode( '\u200b' ); | ||
| // Do not modify to live range. |
There was a problem hiding this comment.
I'd kinda wonder why it matters, i.e. while true that we're mutating the range, we're also following up with a mutation to remove the added node, which means it should be effectively the same. I'm not entirely clear from the conversation of the pull request what impact this change is having.
There was a problem hiding this comment.
We do update the DOM again, but not through the range API which may explain why its not restored.
64d33d7 to
ba32d64
Compare
ba32d64 to
94c4b6b
Compare
…dPress#14906) * Input Interaction: restore collapsing selection before edge calc * Add e2e test * Fix other e2e test * Clean up * Do not modify live range in getRectangleFromRange
Description
Fixes #14871.
Regression caused by #14871.
Specifically, the following code should not have been removed:
gutenberg/packages/dom/src/dom.js
Lines 89 to 95 in 0563f6f
How has this been tested?
Screenshots
Types of changes
Checklist: