Commitabbc93e5Recorded24 Nov 2026Repositoryoriel
Keep a key pressed while a page finishes loading
Message
Before acting on a key in nav mode, the shell asks the page whether an editable element has focus. Events handled while that query runs, such as a load finishing and rewriting the status message, changed the shell state, and the key was then treated as stale and dropped without a notice. Only a change to what the key means now cancels it: the mode, a pending key sequence or count, page focus blocking, the config or the page address.
Changed
packages/oriel/src/oriel/shell.sgl | 2 +-
packages/oriel/src/oriel/shell/focus.sgl | 14 +++++++++++++-
packages/oriel/test/test-shell.sgl | 29 +++++++++++++++++++++++++++++
3 files changed, 43 insertions(+), 2 deletions(-)Diff
packages/oriel/src/oriel/shell.sglmodified
@@ -791,7 +791,7 @@
791
(lambda () (set! focus-checking? #f))))) 792
(lambda () 793
(and (= generation input-generation) (eq? target (current-view))−794
(equal? snapshot state) (not quit?) (not focus-canceled?)))))))+794
(shell-key-context-same? snapshot state) (not quit?) (not focus-canceled?))))))) 795
(define (key! engine event (opts: (admitted #f))) 796
(when (and controls (memq (cadr event) '(press repeat))) 797
((dict-ref controls history-interrupt:) (current-view)))packages/oriel/src/oriel/shell/focus.sglmodified
@@ -1,7 +1,7 @@
1
;;; A focus notification is advisory; first-key ownership has its own check. 2
(define-library (oriel shell focus) 3
(import (sigil dict) (sigil string) (sigil list))−4
(export shell-needs-focus-check? check-page-key-focus page-focus-source)+4
(export shell-needs-focus-check? check-page-key-focus shell-key-context-same? page-focus-source) 5
(begin 6
;; Installed in the isolated shell world in every frame. Programmatic 7
;; focus cannot claim PAGE; only a trusted pointer interaction may do so.@@ -40,6 +40,18 @@
40
(not (member (list-ref event 2) '("Escape" "i"))) 41
(not (and (memq 'control (list-ref event 4)) 42
(member (list-ref event 2) '("g" "v"))))))+43
;; Whether a key pressed in BEFORE still means the same thing in AFTER.+44
;; The focus query pumps page events, so the status message, the title+45
;; or a link preview can change while it runs; those leave the key alone.+46
;; A mode change, a pending key sequence or count, Escape's page-focus+47
;; block, a new keymap or a navigation to another address cancel it.+48
(define (shell-key-context-same? before after)+49
(and (eq? (dict-ref before mode:) (dict-ref after mode:))+50
(equal? (dict-ref before key-sequence: '()) (dict-ref after key-sequence: '()))+51
(eq? (dict-ref before page-focus-blocked?: #f) (dict-ref after page-focus-blocked?: #f))+52
(equal? (dict-ref before count: "") (dict-ref after count: ""))+53
(eq? (dict-ref before config: #f) (dict-ref after config: #f))+54
(equal? (dict-ref before uri: #f) (dict-ref after uri: #f)))) 55
(define (check-page-key-focus state event query still-current?) 56
(if (not (shell-needs-focus-check? state event)) event 57
(let ((answer (guard (failure (#t 'unknown)) (query))))packages/oriel/test/test-shell.sglmodified
@@ -131,6 +131,35 @@
131
(assert-true (shell-needs-focus-check? state (key "w" mods: '(control)))) 132
(assert-equal (list (list 'page (key "w" mods: '(control)))) 133
(cdr (shell-key state (append (key "w" mods: '(control)) (list (dict page-focus: 'focused))))))))+134
(test "a load finishing during the focus query keeps the key"+135
;; The query pumps page events; load-changed finished rewrites message:.+136
(define (checked-during state event change)+137
(let ((snapshot state) (current state))+138
(cons (check-page-key-focus state event+139
(lambda () (set! current (change current)) #f)+140
(lambda () (shell-key-context-same? snapshot current)))+141
current)))+142
(define (finished state)+143
(dict-set state message: "o: open i: PAGE H/L: history r: reload :quit"))+144
(let* ((state (dict-set (make-shell-state "about:blank") message: "Loading..."))+145
(close (checked-during state (key "D" mods: '(shift)) finished))+146
(open (checked-during state (key "O" mods: '(shift)) finished))+147
(noticed (checked-during state (key "D" mods: '(shift))+148
(lambda (state) (dict-set state notice: "Downloaded report.txt")))))+149
(assert-equal '((close-tab)) (cdr (shell-key (cdr close) (car close))))+150
(assert-equal 'cmd (dict-ref (car (shell-key (cdr open) (car open))) mode:))+151
(assert-equal '((close-tab)) (cdr (shell-key (cdr noticed) (car noticed)))))+152
(let* ((state (make-shell-state "about:blank"))+153
(escaped (checked-during state (key "D" mods: '(shift))+154
(lambda (state) (car (shell-key state (key "Escape"))))))+155
(navigated (checked-during state (key "D" mods: '(shift))+156
(lambda (state) (dict-set state uri: "https://example.org/next"))))+157
(moded (checked-during state (key "D" mods: '(shift))+158
(lambda (state) (dict-set state mode: 'page)))))+159
(for-each (lambda (answer)+160
(assert-equal 'stale (dict-ref (list-ref (car answer) 6) page-focus:))+161
(assert-equal '() (cdr (shell-key (cdr answer) (car answer)))))+162
(list escaped navigated moded)))) 163
(test "bounded evaluation preserves existing callers and rejects invalid deadlines" 164
(let* ((engine (make-fake-engine #{})) 165
(view (engine-make-view engine (engine-make-session engine #{}) #{})))