Skip to content

Commit

Permalink
Rich text: remove unnecessary handleSelectionChange call (#48373)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored Feb 24, 2023
1 parent fc4caf8 commit 93ad9a4
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions packages/rich-text/src/component/use-input-and-selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export function useInputAndSelection( props ) {
const { defaultView } = ownerDocument;

let isComposing = false;
let rafId;

function onInput( event ) {
// Do not trigger a change if characters are being composed.
Expand Down Expand Up @@ -113,11 +112,10 @@ export function useInputAndSelection( props ) {
}

/**
* Syncs the selection to local state. A callback for the `selectionchange`
* native events, `keyup`, `mouseup` and `touchend` synthetic events, and
* animation frames after the `focus` event.
* Syncs the selection to local state. A callback for the
* `selectionchange`, `keyup`, `mouseup` and `touchend` events.
*
* @param {Event|DOMHighResTimeStamp} event
* @param {Event} event
*/
function handleSelectionChange( event ) {
const {
Expand Down Expand Up @@ -291,12 +289,6 @@ export function useInputAndSelection( props ) {
applyRecord( record.current );
onSelectionChange( record.current.start, record.current.end );
}

// Update selection as soon as possible, which is at the next animation
// frame. The event listener for selection changes may be added too late
// at this point, but this focus event is still too early to calculate
// the selection.
rafId = defaultView.requestAnimationFrame( handleSelectionChange );
}

element.addEventListener( 'input', onInput );
Expand Down Expand Up @@ -329,7 +321,6 @@ export function useInputAndSelection( props ) {
'selectionchange',
handleSelectionChange
);
defaultView.cancelAnimationFrame( rafId );
};
}, [] );
}

1 comment on commit 93ad9a4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 93ad9a4.
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.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4260693967
📝 Reported issues:

Please sign in to comment.