summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--starling/kernel.scm18
-rw-r--r--starling/minibuffer.scm19
2 files changed, 20 insertions, 17 deletions
diff --git a/starling/kernel.scm b/starling/kernel.scm
index e6658ca..23d1bad 100644
--- a/starling/kernel.scm
+++ b/starling/kernel.scm
@@ -133,7 +133,8 @@
(default-viewport #:accessor default-viewport)
(avg-frame-time #:accessor avg-frame-time #:init-form 0.0)
(controllers #:accessor controllers #:init-thunk make-hash-table)
- (repl #:accessor repl))
+ (repl #:accessor repl)
+ (minibuffer #:accessor minibuffer))
(define current-kernel (make-parameter #f))
@@ -172,6 +173,10 @@
(make <repl>
#:name 'repl
#:scene-mux kernel))
+ (set! (minibuffer kernel)
+ (make <minibuffer>
+ #:name 'minibuffer
+ #:scene-mux kernel))
(run-script kernel
(forever
(sleep 60)
@@ -180,7 +185,7 @@
(define-method (on-key-press (kernel <kernel>) key modifiers repeat?)
;; Hot keys when in dev mode
(if (and developer-mode?
- (not (or (eq? (current-scene kernel) (& kernel minibuffer))
+ (not (or (eq? (current-scene kernel) (minibuffer kernel))
(eq? (current-scene kernel) (repl kernel)))))
(match key
('backquote
@@ -190,7 +195,14 @@
('x
(if (or (memq 'left-alt modifiers)
(memq 'right-alt modifiers))
- (open-minibuffer kernel)
+ ;; We need to delay the minibuffer by one frame so that
+ ;; the text input event for the "x" character (part of
+ ;; the M-x key shortcut) is not processed by the
+ ;; minibuffer, thus adding an "x" to the user text entry
+ ;; area before the user has actually typed anything.
+ (run-script kernel
+ (sleep 1)
+ (open-minibuffer (minibuffer kernel)))
(next-method)))
('escape (abort-game))
(_ (next-method)))
diff --git a/starling/minibuffer.scm b/starling/minibuffer.scm
index 489ee7e..690445f 100644
--- a/starling/minibuffer.scm
+++ b/starling/minibuffer.scm
@@ -39,7 +39,7 @@
(define-class <minibuffer> (<scene-2d>)
(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)
+ (overlay-scene #:accessor overlay-scene)
(user-text #:accessor user-text #:init-form ""))
(define (minibuffer-commands)
@@ -48,19 +48,9 @@
(define-method (add-minibuffer-command name thunk)
(hash-set! (minibuffer-commands) name thunk))
-(define-method (open-minibuffer scene-mux)
- (let ((minibuffer (make <minibuffer>
- #:name 'minibuffer
- #:scene-mux scene-mux
- #:overlay-scene (current-scene scene-mux))))
- ;; We need to delay the minibuffer by one frame so that the text
- ;; input event for the "x" character (part of the M-x key
- ;; shortcut) is not processed by the minibuffer, thus adding an
- ;; "x" to the user text entry area before the user has actually
- ;; typed anything.
- (run-script scene-mux
- (sleep 1)
- (push-scene scene-mux minibuffer))))
+(define-method (open-minibuffer minibuffer)
+ (set! (overlay-scene minibuffer) (current-scene (scene-mux minibuffer)))
+ (push-scene (scene-mux minibuffer) minibuffer))
(define-method (close-minibuffer (minibuffer <minibuffer>))
(pop-scene (scene-mux minibuffer)))
@@ -68,6 +58,7 @@
(define-method (run-command (minibuffer <minibuffer>))
(let ((thunk (hash-ref (minibuffer-commands) (user-text minibuffer))))
(when (procedure? thunk)
+ (modify-user-text minibuffer "")
(close-minibuffer minibuffer)
(thunk))))