Bug bash 3: solid HUD dialogs, remote stacks deployed from the hub's shell, stopped-on-purpose is not down, the New stack dialog keeps what you typed
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
634e286796
commit
a446a03b7d
+10
-4
@@ -70,11 +70,17 @@ export function NetBar() {
|
||||
}
|
||||
|
||||
// useEscape runs fn when Escape is pressed while active — every menu and dialog closes that way.
|
||||
export function useEscape(fn: () => void, active = true) {
|
||||
// A question (askYes/askText) sits on top of whatever asked it: Escape answers the question and
|
||||
// goes no further, or one key would cancel the question and close the dialog underneath as well.
|
||||
let escapeTaken: Event | null = null
|
||||
export function useEscape(fn: () => void, active = true, isAsk = false) {
|
||||
const ref = useRef(fn); ref.current = fn
|
||||
useEffect(() => {
|
||||
if (!active) return
|
||||
const h = (e: KeyboardEvent) => { if (e.key === 'Escape') ref.current() }
|
||||
const h = (e: KeyboardEvent) => {
|
||||
if (e.key !== 'Escape') return
|
||||
if (isAsk) { escapeTaken = e; ref.current() } else if (asks.length === 0 && escapeTaken !== e) ref.current()
|
||||
}
|
||||
window.addEventListener('keydown', h)
|
||||
return () => window.removeEventListener('keydown', h)
|
||||
}, [active])
|
||||
@@ -103,9 +109,9 @@ function AskBox({ a }: { a: Ask }) {
|
||||
const [val, setVal] = useState(a.input ?? '')
|
||||
const cancel = () => a.done(a.input !== undefined ? null : false)
|
||||
const accept = () => a.done(a.input !== undefined ? val : true)
|
||||
useEscape(cancel)
|
||||
useEscape(cancel, true, true)
|
||||
return (
|
||||
<div className="modal-back" onClick={cancel}>
|
||||
<div className="modal-back ask-back" onClick={cancel}>
|
||||
<form className="modal ask" onClick={(e) => e.stopPropagation()} onSubmit={(e) => { e.preventDefault(); accept() }}>
|
||||
<div className="ask-msg">{a.msg}</div>
|
||||
{a.input !== undefined && <input autoFocus value={val} onChange={(e) => setVal(e.target.value)} onFocus={(e) => e.target.select()} spellCheck={false} autoCapitalize="off" autoCorrect="off" />}
|
||||
|
||||
Reference in New Issue
Block a user