Skip to content

Commit

Permalink
Revert all changes to useAnchor hook
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave authored and draganescu committed Jan 23, 2024
1 parent 25ffdf7 commit 91a766a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/rich-text/src/component/use-anchor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { useState, useLayoutEffect, useCallback } from '@wordpress/element';
import { useState, useLayoutEffect } from '@wordpress/element';

/** @typedef {import('../register-format-type').WPFormat} WPFormat */
/** @typedef {import('../types').RichTextValue} RichTextValue */
Expand Down Expand Up @@ -142,15 +142,17 @@ export function useAnchor( { editableContentElement, settings = {} } ) {
getAnchor( editableContentElement, tagName, className )
);

const callback = useCallback( () => {
setAnchor( getAnchor( editableContentElement, tagName, className ) );
}, [ className, editableContentElement, tagName ] );

useLayoutEffect( () => {
if ( ! editableContentElement ) return;

const { ownerDocument } = editableContentElement;

function callback() {
setAnchor(
getAnchor( editableContentElement, tagName, className )
);
}

function attach() {
ownerDocument.addEventListener( 'selectionchange', callback );
}
Expand All @@ -172,8 +174,7 @@ export function useAnchor( { editableContentElement, settings = {} } ) {
editableContentElement.removeEventListener( 'focusin', attach );
editableContentElement.removeEventListener( 'focusout', detach );
};
}, [ editableContentElement, tagName, className, callback ] );
}, [ editableContentElement, tagName, className ] );

anchor.update = callback;
return anchor;
}

0 comments on commit 91a766a

Please sign in to comment.