summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--starling/minibuffer.scm18
1 files changed, 9 insertions, 9 deletions
diff --git a/starling/minibuffer.scm b/starling/minibuffer.scm
index ed2761b..dd8edbe 100644
--- a/starling/minibuffer.scm
+++ b/starling/minibuffer.scm
@@ -37,7 +37,7 @@
open-minibuffer))
(define-class <minibuffer> (<scene-2d>)
- (commands #:accessor commands #:allocation #:class #:init-form '())
+ (commands #:accessor commands #:allocation #:class #:init-thunk make-hash-table)
(scene-mux #:getter scene-mux #:init-keyword #:scene-mux)
(overlay-scene #:getter overlay-scene #:init-keyword #:overlay-scene)
(user-text #:accessor user-text #:init-form ""))
@@ -46,9 +46,7 @@
(class-slot-ref <minibuffer> 'commands))
(define-method (add-minibuffer-command name thunk)
- (class-slot-set! <minibuffer> 'commands
- (cons (cons name thunk)
- (minibuffer-commands))))
+ (hash-set! (minibuffer-commands) name thunk))
(define-method (open-minibuffer scene-mux)
(let ((minibuffer (make <minibuffer>
@@ -68,7 +66,7 @@
(pop-scene (scene-mux minibuffer)))
(define-method (run-command (minibuffer <minibuffer>))
- (let ((thunk (assoc-ref (minibuffer-commands) (user-text minibuffer))))
+ (let ((thunk (hash-ref (minibuffer-commands) (user-text minibuffer))))
(when (procedure? thunk)
(close-minibuffer minibuffer)
(thunk))))
@@ -87,10 +85,12 @@
(let ((prefix (user-text minibuffer)))
;; Auto-complete if there is a single command name that starts
;; with the characters the user has already typed.
- (match (filter-map (match-lambda
- ((name . _)
- (and (string-prefix? prefix name) name)))
- (minibuffer-commands))
+ (match (hash-fold (lambda (key value prev)
+ (if (string-prefix? prefix key)
+ (cons key prev)
+ prev))
+ '()
+ (minibuffer-commands))
((name)
(modify-user-text minibuffer name))
(_ #f))))