/**
 * Whether the editor should claim a Cmd/Ctrl+Z for app-level block undo/redo.
 *
 * The block canvas is `contentEditable` and routes every edit through the
 * editor's `onInput`/`onChange`, so its native history is ours to own — we want
 * the shortcut there. But the editor chrome also mounts plain text fields (the
 * block inspector's Alt-text input, the inline link popover's URL field). In
 * those, the field's own native undo must win, so we must NOT intercept — the
 * capture-phase handler would otherwise revert a block change and swallow the
 * field's native undo.
 *
 * @param target The keydown event target (`event.target`).
 * @param canvas The block-canvas element (the `__body` ref), or null pre-mount.
 */
export function shouldHandleEditorUndo(
	target: EventTarget | null,
	canvas: HTMLElement | null
): boolean {
	if ( ! ( target instanceof HTMLElement ) ) {
		return true;
	}
	// Anything inside the canvas is the writing surface (RichText) — handle it.
	if ( canvas && canvas.contains( target ) ) {
		return true;
	}
	// Outside the canvas, defer to a focused editable field's native undo.
	return ! target.closest( 'input, textarea, [contenteditable="true"]' );
}
