-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Input Interaction: restore collapsing selection before edge calc #14906
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 |
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.
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.
@@ -209,6 +218,8 @@ export function getRectangleFromRange( range ) { | |||
// See: https://stackoverflow.com/a/6847328/995445 | |||
if ( ! rect ) { | |||
const padNode = document.createTextNode( '\u200b' ); | |||
// Do not modify to live range. | |||
range = range.cloneRange(); |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
// Verify vertical traversal at offset. This has been buggy in the past | |
// where verticality on a blank newline would skip into previous block. | |
await page.keyboard.type( 'Foo' ); | |
await page.keyboard.press( 'ArrowUp' ); | |
await page.keyboard.press( 'ArrowUp' ); | |
await pressKeyTimes( 'ArrowRight', 3 ); | |
await pressKeyTimes( 'Delete', 6 ); | |
await page.keyboard.type( ' text' ); |
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.
packages/dom/src/dom.js
Outdated
@@ -209,6 +218,8 @@ export function getRectangleFromRange( 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: