Skip to content

Commit

Permalink
add fn name
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Nov 11, 2024
1 parent 6495a5c commit e8e864a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion packages/rich-text/src/component/event-listeners/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import formatBoundaries from './format-boundaries';
import deleteHandler from './delete';
import inputAndSelection from './input-and-selection';
import selectionChangeCompat from './selection-change-compat';
import preventFocusCapture from './prevent-focus-capture';
import { preventFocusCapture } from './prevent-focus-capture';

const allEventListeners = [
copyHandler,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
export default () => ( element ) => {
const { ownerDocument } = element;
const { defaultView } = ownerDocument;
export function preventFocusCapture() {
return ( element ) => {
const { ownerDocument } = element;
const { defaultView } = ownerDocument;

let value = null;
let value = null;

function onPointerDown( event ) {
// Abort if the event is default prevented, we will not get a pointer up event.
if ( event.defaultPrevented ) {
return;
function onPointerDown( event ) {
// Abort if the event is default prevented, we will not get a pointer up event.
if ( event.defaultPrevented ) {
return;
}
if ( event.target === element ) {
return;
}
if ( ! event.target.contains( element ) ) {
return;
}
value = element.getAttribute( 'contenteditable' );
element.setAttribute( 'contenteditable', 'false' );
defaultView.getSelection().removeAllRanges();
}
if ( event.target === element ) {
return;
}
if ( ! event.target.contains( element ) ) {
return;
}
value = element.getAttribute( 'contenteditable' );
element.setAttribute( 'contenteditable', 'false' );
defaultView.getSelection().removeAllRanges();
}

function onPointerUp() {
if ( value !== null ) {
element.setAttribute( 'contenteditable', value );
value = null;
function onPointerUp() {
if ( value !== null ) {
element.setAttribute( 'contenteditable', value );
value = null;
}
}
}

defaultView.addEventListener( 'pointerdown', onPointerDown );
defaultView.addEventListener( 'pointerup', onPointerUp );
return () => {
defaultView.removeEventListener( 'pointerdown', onPointerDown );
defaultView.removeEventListener( 'pointerup', onPointerUp );
defaultView.addEventListener( 'pointerdown', onPointerDown );
defaultView.addEventListener( 'pointerup', onPointerUp );
return () => {
defaultView.removeEventListener( 'pointerdown', onPointerDown );
defaultView.removeEventListener( 'pointerup', onPointerUp );
};
};
};
}

0 comments on commit e8e864a

Please sign in to comment.