From b42a4d6193cf72bfa10586d42b837cd3336176ed Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Fri, 16 May 2025 15:29:44 -0400 Subject: [PATCH] fix: Scrolling along edges breaks text editing Existing Gutenberg `preventFocusCapture` logic relies upon `pointerdown` and `pointerup` events for temporarily disabling all text blocks `contenteditable` status. This is down to mitigate issues with block selection for `flex` elements. However, `pointerup` events are not always triggered on touch devices when a touch turns into a swipe. When you scroll with your finger outside of the block canvas, the `pointerup` callback is never invoked. Scrolling twice or more leads to a stale `value` in the callback, and a state where `contenteditable` is perpetually disabled. --- patches/@wordpress+rich-text+7.22.0.patch | 16 ++++++++++++++++ patches/README.md | 4 ++++ 2 files changed, 20 insertions(+) create mode 100644 patches/@wordpress+rich-text+7.22.0.patch diff --git a/patches/@wordpress+rich-text+7.22.0.patch b/patches/@wordpress+rich-text+7.22.0.patch new file mode 100644 index 000000000..8e2160111 --- /dev/null +++ b/patches/@wordpress+rich-text+7.22.0.patch @@ -0,0 +1,16 @@ +diff --git a/node_modules/@wordpress/rich-text/build-module/component/event-listeners/prevent-focus-capture.js b/node_modules/@wordpress/rich-text/build-module/component/event-listeners/prevent-focus-capture.js +index 3b885f5..c2ea3d0 100644 +--- a/node_modules/@wordpress/rich-text/build-module/component/event-listeners/prevent-focus-capture.js ++++ b/node_modules/@wordpress/rich-text/build-module/component/event-listeners/prevent-focus-capture.js +@@ -36,9 +36,11 @@ export function preventFocusCapture() { + } + defaultView.addEventListener('pointerdown', onPointerDown); + defaultView.addEventListener('pointerup', onPointerUp); ++ defaultView.addEventListener('pointercancel', onPointerUp); + return () => { + defaultView.removeEventListener('pointerdown', onPointerDown); + defaultView.removeEventListener('pointerup', onPointerUp); ++ defaultView.removeEventListener('pointercancel', onPointerUp); + }; + }; + } diff --git a/patches/README.md b/patches/README.md index 64130f636..39fde5f56 100644 --- a/patches/README.md +++ b/patches/README.md @@ -10,3 +10,7 @@ Existing patches should be described and justified here. - Expose an `open` prop on the `Inserter` component, allowing toggling the inserter visibility via the quick inserter's "Browse all" button. - Disable `stripExperimentalSettings` in the `BlockEditorProvider` component so that the Patterns and Media inserter tabs function. + +### `@wordpress/rich-text` + +- Fix `preventFocusCapture` causing uneditable text blocks on touch devices when scrolling by swiping outside of the block canvas--e.g., along the edge of the screen.