From 7820b45308e1b363244e131d5c57c3cef3ee1506 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 2 Aug 2015 12:29:28 -0700 Subject: 1918 --- edit.mu | 144 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 72 insertions(+), 72 deletions(-) (limited to 'edit.mu') diff --git a/edit.mu b/edit.mu index a11d449c..a19fd07d 100644 --- a/edit.mu +++ b/edit.mu @@ -2371,6 +2371,78 @@ recipe new-programming-environment [ reply result ] +recipe event-loop [ + local-scope + screen:address <- next-ingredient + console:address <- next-ingredient + env:address:programming-environment-data <- next-ingredient + recipes:address:editor-data <- get *env, recipes:offset + current-sandbox:address:editor-data <- get *env, current-sandbox:offset + sandbox-in-focus?:address:boolean <- get-address *env, sandbox-in-focus?:offset + { + # looping over each (keyboard or touch) event as it occurs + +next-event + e:event, console, found?:boolean, quit?:boolean <- read-event console + loop-unless found? + break-if quit? # only in tests + trace [app], [next-event] + # check for global events that will trigger regardless of which editor has focus + { + k:address:number <- maybe-convert e:event, keycode:variant + break-unless k + +global-keypress + } + { + c:address:character <- maybe-convert e:event, text:variant + break-unless c + +global-type + # ctrl-n? - switch focus + { + ctrl-n?:boolean <- equal *c, 14/ctrl-n + break-unless ctrl-n? + *sandbox-in-focus? <- not *sandbox-in-focus? + update-cursor screen, recipes, current-sandbox, *sandbox-in-focus? + show-screen screen + loop +next-event:label + } + } + # 'touch' event - send to both sides, see what picks it up + { + t:address:touch-event <- maybe-convert e:event, touch:variant + break-unless t + # ignore all but 'left-click' events for now + # todo: test this + touch-type:number <- get *t, type:offset + is-left-click?:boolean <- equal touch-type, 65513/mouse-left + loop-unless is-left-click?, +next-event:label + # later exceptions for non-editor touches will go here + +global-touch + # send to both editors + _ <- move-cursor-in-editor screen, recipes, *t + *sandbox-in-focus? <- move-cursor-in-editor screen, current-sandbox, *t + render-minimal screen, env + loop +next-event:label + } + # if it's not global and not a touch event, send to appropriate editor + { + { + break-if *sandbox-in-focus? + handle-event screen, console, recipes, e:event + } + { + break-unless *sandbox-in-focus? + handle-event screen, console, current-sandbox, e:event + } + # optimization: refresh screen only if no more events + # todo: test this + more-events?:boolean <- has-more-events? console + break-if more-events? + render-minimal screen, env + } + loop + } +] + scenario point-at-multiple-editors [ $close-trace assume-screen 30/width, 5/height @@ -2570,78 +2642,6 @@ recipe render-recipes [ reply screen/same-as-ingredient:0 ] -recipe event-loop [ - local-scope - screen:address <- next-ingredient - console:address <- next-ingredient - env:address:programming-environment-data <- next-ingredient - recipes:address:editor-data <- get *env, recipes:offset - current-sandbox:address:editor-data <- get *env, current-sandbox:offset - sandbox-in-focus?:address:boolean <- get-address *env, sandbox-in-focus?:offset - { - # looping over each (keyboard or touch) event as it occurs - +next-event - e:event, console, found?:boolean, quit?:boolean <- read-event console - loop-unless found? - break-if quit? # only in tests - trace [app], [next-event] - # check for global events that will trigger regardless of which editor has focus - { - k:address:number <- maybe-convert e:event, keycode:variant - break-unless k - +global-keypress - } - { - c:address:character <- maybe-convert e:event, text:variant - break-unless c - +global-type - # ctrl-n? - switch focus - { - ctrl-n?:boolean <- equal *c, 14/ctrl-n - break-unless ctrl-n? - *sandbox-in-focus? <- not *sandbox-in-focus? - update-cursor screen, recipes, current-sandbox, *sandbox-in-focus? - show-screen screen - loop +next-event:label - } - } - # 'touch' event - send to both sides, see what picks it up - { - t:address:touch-event <- maybe-convert e:event, touch:variant - break-unless t - # ignore all but 'left-click' events for now - # todo: test this - touch-type:number <- get *t, type:offset - is-left-click?:boolean <- equal touch-type, 65513/mouse-left - loop-unless is-left-click?, +next-event:label - # later exceptions for non-editor touches will go here - +global-touch - # send to both editors - _ <- move-cursor-in-editor screen, recipes, *t - *sandbox-in-focus? <- move-cursor-in-editor screen, current-sandbox, *t - render-minimal screen, env - loop +next-event:label - } - # if it's not global and not a touch event, send to appropriate editor - { - { - break-if *sandbox-in-focus? - handle-event screen, console, recipes, e:event - } - { - break-unless *sandbox-in-focus? - handle-event screen, console, current-sandbox, e:event - } - # optimization: refresh screen only if no more events - # todo: test this - more-events?:boolean <- has-more-events? console - break-if more-events? - render-minimal screen, env - } - loop - } -] - # helper for testing a single editor recipe update-cursor [ -- cgit 1.4.1-2-gfad0