PluginProbe
Extendify / 3.1.5
Extendify v3.1.5
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / QuickEdit / lib / escape-rule.js

escape-rule.js in Extendify 3.1.5, at src/QuickEdit/lib/escape-rule.js

35 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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