Skip to content

Fix iOS tap into a quote jumping to the caret's block when it's off screen - #86923

Open
ellatrix wants to merge 3 commits into
trunkfrom
fix/ios-tap-scrolls-to-old-caret
Open

ellatrix wants to merge 3 commits into
trunkfrom
fix/ios-tap-scrolls-to-old-caret

Conversation

@ellatrix

@ellatrix ellatrix commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

What?

On iOS, tapping a block that is edited as its own field, like a paragraph in a quote or an image caption, now places the caret there when the caret was in a block that is scrolled out of view. Before, the page jumped and the tap landed on a different block.

Why?

A tap from a block the canvas edits (a heading) into a block edited as its own field (a paragraph in a quote) has to move focus from the canvas to that field. On iOS, moving focus soon after a tap makes WebKit reset its text gestures, and UIKit then repeats the tap at the page's top left corner, which moves the caret there. #86549 worked around this by moving focus on touch start, before the tap, but then it cannot tell a tap from a scroll, and it focused the field with the caret: when that field was off screen, iOS scrolled to it, ignoring preventScroll, so the tap landed on another block.

How?

  1. useClickSelection moves focus on mousedown instead of pointerdown. A mouse places the caret in mousedown's default action, so this is still in time for it, and a touch only fires mousedown once it is a tap. Nothing runs on touch start, so taps and scrolls are native.
  2. A new useRestoreTapCaret remembers the caret when focus moves from the canvas to a field, and puts it back if the caret then leaves the focused field. Only the repeated tap does that, since it changes the selection but not focus. It can go once WebKit fixes the repeat.

Testing Instructions

Open in Playground: a post with a heading, a quote and paragraphs below them, open in the editor.

  1. In Safari on an iPhone, scroll down and tap the end of the last paragraph.
  2. Scroll back up until that paragraph is out of view.
  3. Tap the start of the quote and type.

On trunk, the page jumps and the text goes elsewhere. With this PR, it goes at the start of the quote.

Also check what #86279 fixed: tap the end of a heading, then the quote, and type. The text goes into the quote.

New iOS test testTapIntoQuoteWithCaretOffScreenPlacesCaret in test/ios/SafariTests/SelectionTests.swift: it fails on trunk ("The quote did not get the X"). With this change, it and the #86279 test testTapFromHeadingIntoQuoteWithoutIframePlacesCaret pass 10 of 10 runs on iOS 27 and on iOS 26.5.

Testing Instructions for Keyboard

Unchanged: the change only affects pressing with a pointer.

Screenshots or screencast

iOS 27 simulator, recorded while testTapIntoQuoteWithCaretOffScreenPlacesCaret runs: the caret is in the last paragraph, the page is scrolled up (sped up 8x), then the test taps the quote and types X.

Before (trunk) After
The page jumps back down and the X lands in another paragraph. The X lands in the quote.
before-trunk.mp4
after-pr.mp4

Use of AI Tools

Investigated and written with Claude Code: reproduced on an iPhone, wrote the iOS test, and ran the iOS and end-to-end tests.

🤖 Generated with Claude Code

Pressing a block that is edited on its own element while the canvas is
the editing host focused the field with the caret first. When that field
was scrolled out of view, iOS scrolled to it, and the tap landed on
another block. Focus the pressed field instead, and for a touch only on
pointerup, once it is a tap rather than a scroll.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ellatrix ellatrix added the [Type] Bug An existing feature does not function as intended label Nov 17, 2026
@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ellatrix <ellatrix@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +51 B (0%)

Total Size: 8.66 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 555 kB +51 B (+0.01%)

9e0f8a6 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 55c38e1 trunk % Change
timeToFirstByte 42.45 ms +13.19% -4.36% 42.6 ms +16.9% -4.81% -0.35%
largestContentfulPaint 70 ms +8.57% -8.57% 70 ms +2.86% -5.71% 0%
lcpMinusTtfb 24.25 ms +27.84% -6.39% 23.95 ms +25.68% -7.1% 1.25%
wpBeforeTemplate 22.02 ms +11.85% -3.32% 22.15 ms +12.14% -1.94% -0.59%
wpTemplate 17.1 ms +5.15% -5.26% 16.81 ms +5.71% -5.59% 1.73%
wpTotal 39.18 ms +13.58% -4.13% 39.09 ms +13.61% -3.76% 0.23%
wpMemoryUsage 7.75 MB +0% -0% 7.71 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 55c38e1 trunk % Change
timeToFirstByte 35.05 ms +12.27% -1.85% 34.85 ms +7.46% -2.87% 0.57%
largestContentfulPaint 64 ms +6.25% -0% 62 ms +9.68% -3.23% 3.23%
lcpMinusTtfb 28.65 ms +2.27% -4.89% 26.5 ms +11.13% -1.89% 8.11%
wpBeforeTemplate 19.06 ms +19.2% -0.63% 18.93 ms +9.46% -1.22% 0.69%
wpTemplate 13.32 ms +5.93% -5.63% 12.86 ms +4.2% -3.27% 3.58%
wpTotal 32.23 ms +12.78% -1.37% 32.19 ms +6.46% -2.67% 0.12%
wpMemoryUsage 6.44 MB +0% -0% 6.40 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 55c38e1 trunk % Change
mediaProcessingJpeg 323.14 ms +1% -0.26% 323.7 ms +1.03% -0.45% -0.17%
mediaProcessingAvif 4845.94 ms +0.14% -0.24% 4849.19 ms +0.32% -0.36% -0.07%
mediaProcessingJpegToAvif 3375.63 ms +0.22% -0.43% 3397.36 ms +0.19% -0.62% -0.64%

media-upload

Metric 55c38e1 trunk % Change
jpegUploadProcessing 1478.75 ms +1.45% -2.43% 1445.76 ms +0.61% -0.57% 2.28%
pngUploadProcessing 236.33 ms +2.73% -4.49% 233.88 ms +4.55% -7.82% 1.05%
largeJpegUploadProcessing 1441.33 ms +0.16% -1.58% 1434.37 ms +0.27% -0.17% 0.49%
multipleImageUploadProcessing 1516.41 ms +0.48% -2.51% 1504.88 ms +0.59% -0.97% 0.77%

post-editor

Metric 55c38e1 trunk % Change
serverResponse 477.55 ms +4.07% -5.05% 498.36 ms +0.74% -9.39% -4.18%
firstPaint 413.81 ms +8.89% -0.92% 426.67 ms +9.05% -6.51% -3.01%
domContentLoaded 834.16 ms +2.72% -2.38% 835.06 ms +1.65% -1.16% -0.11%
loaded 835.33 ms +2.72% -2.39% 836.18 ms +1.63% -1.18% -0.1%
firstContentfulPaint 476.47 ms +2.78% -2.17% 470.4 ms +1.8% -1.86% 1.29%
firstBlock 2232.48 ms +1.83% -1.39% 2239.59 ms +2% -0.86% -0.32%
type 17.89 ms +9.78% -12.74% 19.13 ms +7.68% -6.33% -6.48%
typeWithoutInspector 17.37 ms +4.84% -10.94% 19.7 ms +10.81% -4.06% -11.83%
typeWithTopToolbar 23 ms +10.52% -9.96% 25.25 ms +1.82% -2.89% -8.91%
typeContainer 8.68 ms +5.3% -16.82% 8.5 ms +12% -14.94% 2.12%
focus 128.65 ms +4.38% -1.69% 129.3 ms +4.08% -6.09% -0.5%
firstFocus 275.31 ms +0% -0% 305.08 ms +0% -0% -9.76%
selectAll 429.54 ms +5.35% -0.11% 425.96 ms +1.66% -0.78% 0.84%
undo 29.23 ms +8.59% -2.91% 32.06 ms +3.31% -10.54% -8.83%
listViewOpen 79.26 ms +8.89% -3.58% 82.03 ms +6.58% -6.89% -3.38%
inserterOpen 43.62 ms +9.42% -5.32% 42.05 ms +8.61% -1.47% 3.73%
inserterHover 12.25 ms +12.08% -9.71% 11.69 ms +13% -8.38% 4.79%
inserterSearch 8.46 ms +5.32% -3.55% 8.38 ms +11.1% -5.61% 0.95%
loadPatterns 677.76 ms +1.2% -5.27% 690.12 ms +2.38% -2.91% -1.79%
wpTotal 467.78 ms +4.17% -5.14% 488.51 ms +0.78% -9.6% -4.24%
wpMemoryUsage 14.81 MB +0% -0% 14.77 MB +0% -0% 0.26%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 55c38e1 trunk % Change
serverResponse 307.34 ms +6.61% -6.4% 317.3 ms +1.28% -9.99% -3.14%
firstPaint 335.04 ms +12.01% -6.23% 360.59 ms +4.99% -15.99% -7.09%
domContentLoaded 667.78 ms +2.93% -1.93% 658.45 ms +0.22% -1.13% 1.42%
loaded 668.68 ms +2.91% -1.95% 659.24 ms +0.23% -1.13% 1.43%
firstContentfulPaint 377.83 ms +8.05% -1.36% 375.43 ms +1.86% -1.94% 0.64%
firstBlock 2031.28 ms +1.17% -0.48% 2005.99 ms +1.81% -0.68% 1.26%
type 16.2 ms +4.57% -18.58% 16.53 ms +7.14% -7.56% -2%
navigate 95.11 ms +12.49% -1.24% 102.48 ms +11.73% -9.97% -7.19%
loadPatterns 1147.03 ms +11.44% -15.26% 1125.09 ms +5.85% -5.08% 1.95%
loadPages 1002.91 ms +2.11% -6.5% 991.27 ms +1.87% -5.27% 1.17%
wpTotal 298.97 ms +6.79% -6.61% 308.79 ms +1.4% -10.25% -3.18%
wpMemoryUsage 12.82 MB +0% -0% 12.79 MB +0% -0% 0.26%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

9e0f8a6 Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

List in /test/e2e/specs/editor/blocks/query.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 22
+ Received  +  1

  Array [
    Object {
-     "innerBlocks": Array [
-       Object {
-         "innerBlocks": Array [
-           Object {
-             "name": "core/post-title",
-           },
-           Object {
-             "name": "core/post-featured-image",
-           },
-           Object {
-             "name": "core/post-excerpt",
-           },
-           Object {
-             "name": "core/separator",
-           },
-           Object {
-             "name": "core/post-date",
-           },
-         ],
-         "name": "core/post-template",
-       },
-     ],
+     "innerBlocks": Array [],
      "name": "core/query",
    },
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/query.spec.js:226:42
can use focal point picker to set the focal point of the cover image in /test/e2e/specs/editor/blocks/cover.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 4
+ Received  + 1

  Array [
    Object {
      "attributes": Object {
-       "focalPoint": Object {
-         "x": 0.2,
-         "y": 0.3,
-       },
+       "focalPoint": undefined,
      },
      "name": "core/cover",
    },
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/cover.spec.js:433:41
does not select blocks in the canvas preview when editing from the sidebar in /test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator: getByRole('combobox', { name: 'Search or type URL' })
Expected: focused
Timeout: 5000ms
Error: element(s) not found

Call log:
  - Expect "toBeFocused" getByRole('combobox', { name: 'Search or type URL' }) with timeout 5000ms
  - waiting for getByRole('combobox', { name: 'Search or type URL' })

    at LinkControl.useLinkControlSearch (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:416:47)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:179:21
should arrow up into empty columns in /test/e2e/specs/editor/blocks/columns.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 0
+ Received  + 7

@@ -1,9 +1,16 @@
  Array [
    Object {
      "innerBlocks": Array [
        Object {
+         "attributes": Object {},
+         "innerBlocks": Array [],
+         "name": "core/column",
+       },
+       Object {
+         "attributes": Object {},
+         "innerBlocks": Array [],
          "name": "core/column",
        },
      ],
      "name": "core/columns",
    },

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/columns.spec.js:349:41
should reset a named font size using input field in /test/e2e/specs/editor/various/font-size-picker.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:paragraph {"fontSize":"small"} -->
+ <!-- wp:paragraph {"fontSize":"tiny"} -->
- <p class="has-small-font-size">Paragraph with font size reset using input field</p>
+ <p class="has-tiny-font-size">Paragraph with font size reset using input field</p>
  <!-- /wp:paragraph -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/font-size-picker.spec.js:216:6
should reset a named font size using the tools panel menu in /test/e2e/specs/editor/various/font-size-picker.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:paragraph {"fontSize":"medium"} -->
+ <!-- wp:paragraph {"fontSize":"small"} -->
- <p class="has-medium-font-size">Paragraph with font size reset using tools panel menu</p>
+ <p class="has-small-font-size">Paragraph with font size reset using tools panel menu</p>
  <!-- /wp:paragraph -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/font-size-picker.spec.js:178:6
should select synced pattern in /test/e2e/specs/editor/various/writing-flow.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]') with timeout 5000ms
  - waiting for locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]')
    14 × locator resolved to <div tabindex="0" role="document" draggable="true" data-title="Pattern" data-type="core/block" data-is-drop-zone="true" aria-label="Block: Pattern" id="block-10aa87c3-56ef-4619-865e-c5a54b1b810e" data-block="10aa87c3-56ef-4619-865e-c5a54b1b810e" class="block-editor-block-list__block wp-block is-selected is-reusable block-library-block__reusable-block-container wp-block-block block-editor-block-list__layout">…</div>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/writing-flow.spec.js:1464:5

9e0f8a6 Run

ellatrix and others added 2 commits November 16, 2026 21:31
A touch may become a scroll, so the press code now runs for a mouse only.
On iOS, moving focus soon after a tap makes WebKit repeat the tap at the
page's top left corner, moving the caret out of the field. Put it back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The browser places a mouse's caret in mousedown's default action, so the
press code runs there, with no pointer type check. A touch's mousedown
comes once it is known to be a tap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ellatrix ellatrix added the Backport to WP 7.2 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Nov 18, 2026
@ellatrix
ellatrix marked this pull request as ready for review November 18, 2026 00:24

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport to WP 7.2 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta [Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant