| 1 |
// Pure Esc decision for the global keydown handler. Wiring (listener |
| 2 |
// attach, stopPropagation, store mutations) lives in global-escape.js. |
| 3 |
// See click-rule.js's module header for the full unified-selector |
| 4 |
// contract this is one piece of. |
| 5 |
// |
| 6 |
// Priority order matches the user-facing contract: |
| 7 |
// 1. agent block + QE on the SAME block → clear both in one keypress |
| 8 |
// (two-pill click stages both; collapsing the unwind keeps Esc as |
| 9 |
// a single dismissal gesture rather than the user pressing twice) |
| 10 |
// 2. agent block staged → clear it (also cancels the in-flight workflow) |
| 11 |
// 3. QE selection set → clear it |
| 12 |
// 4. committedSelection → clear it (sticky pre-pill-action commit) |
| 13 |
// 5. otherwise → noop (Esc must not flip edit mode off) |
| 14 |
// |
| 15 |
// Edit mode off is a pass-through: the per-surface Esc handlers |
| 16 |
// (BlockTextEditor capture-phase, WP <Modal>, image-menu) keep working |
| 17 |
// because the global handler only consumes Esc while edit mode is on. |
| 18 |
|
| 19 |
export const decideEscapeAction = ({ |
| 20 |
editModeOn, |
| 21 |
hasAgentBlock, |
| 22 |
hasQuickEditSelection, |
| 23 |
hasCommittedSelection, |
| 24 |
sameBlock = false, |
| 25 |
}) => { |
| 26 |
if (!editModeOn) return { action: 'pass-through' }; |
| 27 |
if (hasAgentBlock && hasQuickEditSelection && sameBlock) { |
| 28 |
return { action: 'clear-selection-and-agent-block' }; |
| 29 |
} |
| 30 |
if (hasAgentBlock) return { action: 'clear-agent-block' }; |
| 31 |
if (hasQuickEditSelection) return { action: 'clear-selection' }; |
| 32 |
if (hasCommittedSelection) return { action: 'clear-committed-selection' }; |
| 33 |
return { action: 'noop' }; |
| 34 |
}; |
| 35 |
|