diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-11-28 01:13:59 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-11-28 01:13:59 -0800 |
commit | c76b0066fb2ae01a28630662cb04a043cc5841cb (patch) | |
tree | fce1fcfeb4521850bf775a3e71b4cad9708a1de5 | |
parent | 06ef635e8a4cbd17e43561809ed58691da6f18d7 (diff) | |
download | mu-c76b0066fb2ae01a28630662cb04a043cc5841cb.tar.gz |
3700
Reorder products of some functions in the edit/ and sandbox/ apps. My recent realization: always return 'real' products before ones that just indicate an ingredient is mutable.
-rw-r--r-- | edit/002-typing.mu | 48 | ||||
-rw-r--r-- | edit/003-shortcuts.mu | 128 | ||||
-rw-r--r-- | edit/004-programming-environment.mu | 4 | ||||
-rw-r--r-- | edit/012-editor-undo.mu | 4 | ||||
-rw-r--r-- | html/edit/002-typing.mu.html | 48 | ||||
-rw-r--r-- | html/edit/003-shortcuts.mu.html | 128 | ||||
-rw-r--r-- | html/edit/004-programming-environment.mu.html | 4 | ||||
-rw-r--r-- | html/edit/012-editor-undo.mu.html | 4 | ||||
-rw-r--r-- | sandbox/002-typing.mu | 48 | ||||
-rw-r--r-- | sandbox/003-shortcuts.mu | 86 | ||||
-rw-r--r-- | sandbox/004-programming-environment.mu | 2 | ||||
-rw-r--r-- | sandbox/012-editor-undo.mu | 4 |
12 files changed, 193 insertions, 315 deletions
diff --git a/edit/002-typing.mu b/edit/002-typing.mu index a584e6a3..4f704f0d 100644 --- a/edit/002-typing.mu +++ b/edit/002-typing.mu @@ -34,7 +34,7 @@ def editor-event-loop screen:&:screen, console:&:console, editor:&:editor -> scr # keyboard events { break-if is-touch? - screen, editor, go-render?:bool <- handle-keyboard-event screen, editor, e + go-render?:bool <- handle-keyboard-event screen, editor, e { break-unless go-render? screen <- editor-render screen, editor @@ -161,11 +161,10 @@ def snap-cursor screen:&:screen, editor:&:editor, target-row:num, target-column: # Process an event 'e' and try to minimally update the screen. # Set 'go-render?' to true to indicate the caller must perform a non-minimal update. -def handle-keyboard-event screen:&:screen, editor:&:editor, e:event -> screen:&:screen, editor:&:editor, go-render?:bool [ +def handle-keyboard-event screen:&:screen, editor:&:editor, e:event -> go-render?:bool, screen:&:screen, editor:&:editor [ local-scope load-ingredients - go-render? <- copy 0/false - return-unless editor + return-unless editor, 0/don't-render screen-width:num <- screen-width screen screen-height:num <- screen-height screen left:num <- get *editor, left:offset @@ -184,11 +183,10 @@ def handle-keyboard-event screen:&:screen, editor:&:editor, e:event -> screen:&: <handle-special-character> # ignore any other special characters regular-character?:bool <- greater-or-equal c, 32/space - go-render? <- copy 0/false - return-unless regular-character? + return-unless regular-character?, 0/don't-render # otherwise type it in <insert-character-begin> - editor, screen, go-render?:bool <- insert-at-cursor editor, c, screen + go-render? <- insert-at-cursor editor, c, screen <insert-character-end> return } @@ -197,11 +195,10 @@ def handle-keyboard-event screen:&:screen, editor:&:editor, e:event -> screen:&: assert is-keycode?, [event was of unknown type; neither keyboard nor mouse] # handlers for each special key will go here <handle-special-key> - go-render? <- copy 1/true - return + return 1/go-render ] -def insert-at-cursor editor:&:editor, c:char, screen:&:screen -> editor:&:editor, screen:&:screen, go-render?:bool [ +def insert-at-cursor editor:&:editor, c:char, screen:&:screen -> go-render?:bool, editor:&:editor, screen:&:screen [ local-scope load-ingredients before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset @@ -233,8 +230,7 @@ def insert-at-cursor editor:&:editor, c:char, screen:&:screen -> editor:&:editor break-if overflow? move-cursor screen, save-row, save-column print screen, c - go-render? <- copy 0/false - return + return 0/don't-render } { # not at right margin? print the character and rest of line @@ -246,9 +242,8 @@ def insert-at-cursor editor:&:editor, c:char, screen:&:screen -> editor:&:editor curr-column:num <- copy save-column { # hit right margin? give up and let caller render - go-render? <- copy 1/true at-right?:bool <- greater-than curr-column, right - return-if at-right? + return-if at-right?, 1/go-render break-unless curr # newline? done. currc:char <- get *curr, value:offset @@ -259,11 +254,9 @@ def insert-at-cursor editor:&:editor, c:char, screen:&:screen -> editor:&:editor curr <- next curr loop } - go-render? <- copy 0/false - return + return 0/don't-render } - go-render? <- copy 1/true - return + return 1/go-render ] # helper for tests @@ -740,8 +733,7 @@ after <insert-character-special-case> [ break-unless below-screen? <scroll-down> } - go-render? <- copy 1/true - return + return 1/go-render } ] @@ -863,14 +855,13 @@ after <handle-special-character> [ newline?:bool <- equal c, 10/newline break-unless newline? <insert-enter-begin> - editor <- insert-new-line-and-indent editor, screen + insert-new-line-and-indent editor, screen <insert-enter-end> - go-render? <- copy 1/true - return + return 1/go-render } ] -def insert-new-line-and-indent editor:&:editor, screen:&:screen -> editor:&:editor, screen:&:screen, go-render?:bool [ +def insert-new-line-and-indent editor:&:editor, screen:&:screen -> editor:&:editor, screen:&:screen [ local-scope load-ingredients cursor-row:num <- get *editor, cursor-row:offset @@ -892,7 +883,6 @@ def insert-new-line-and-indent editor:&:editor, screen:&:screen -> editor:&:edit below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal, never greater break-unless below-screen? <scroll-down> - go-render? <- copy 1/true cursor-row <- subtract cursor-row, 1 # bring back into screen range *editor <- put *editor, cursor-row:offset, cursor-row } @@ -906,7 +896,7 @@ def insert-new-line-and-indent editor:&:editor, screen:&:screen -> editor:&:edit { indent-done?:bool <- greater-or-equal i, indent break-if indent-done? - editor, screen, go-render?:bool <- insert-at-cursor editor, 32/space, screen + insert-at-cursor editor, 32/space, screen i <- add i, 1 loop } @@ -1048,8 +1038,7 @@ after <handle-special-key> [ paste-start?:bool <- equal k, 65507/paste-start break-unless paste-start? *editor <- put *editor, indent?:offset, 0/false - go-render? <- copy 1/true - return + return 1/go-render } ] @@ -1058,8 +1047,7 @@ after <handle-special-key> [ paste-end?:bool <- equal k, 65506/paste-end break-unless paste-end? *editor <- put *editor, indent?:offset, 1/true - go-render? <- copy 1/true - return + return 1/go-render } ] diff --git a/edit/003-shortcuts.mu b/edit/003-shortcuts.mu index b747a869..1b352fdd 100644 --- a/edit/003-shortcuts.mu +++ b/edit/003-shortcuts.mu @@ -29,11 +29,10 @@ after <handle-special-character> [ tab?:bool <- equal c, 9/tab break-unless tab? <insert-character-begin> - editor, screen, go-render?:bool <- insert-at-cursor editor, 32/space, screen - editor, screen, go-render?:bool <- insert-at-cursor editor, 32/space, screen + insert-at-cursor editor, 32/space, screen + insert-at-cursor editor, 32/space, screen <insert-character-end> - go-render? <- copy 1/true - return + return 1/go-render } ] @@ -72,7 +71,7 @@ after <handle-special-character> [ delete-previous-character?:bool <- equal c, 8/backspace break-unless delete-previous-character? <backspace-character-begin> - editor, screen, go-render?:bool, backspaced-cell:&:duplex-list:char <- delete-before-cursor editor, screen + go-render?:bool, backspaced-cell:&:duplex-list:char <- delete-before-cursor editor, screen <backspace-character-end> return } @@ -81,31 +80,28 @@ after <handle-special-character> [ # return values: # go-render? - whether caller needs to update the screen # backspaced-cell - value deleted (or 0 if nothing was deleted) so we can save it for undo, etc. -def delete-before-cursor editor:&:editor, screen:&:screen -> editor:&:editor, screen:&:screen, go-render?:bool, backspaced-cell:&:duplex-list:char [ +def delete-before-cursor editor:&:editor, screen:&:screen -> go-render?:bool, backspaced-cell:&:duplex-list:char, editor:&:editor, screen:&:screen [ local-scope load-ingredients before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset data:&:duplex-list:char <- get *editor, data:offset # if at start of text (before-cursor at § sentinel), return prev:&:duplex-list:char <- prev before-cursor - go-render?, backspaced-cell <- copy 0/no-more-render, 0/nothing-deleted - return-unless prev + return-unless prev, 0/no-more-render, 0/nothing-deleted trace 10, [app], [delete-before-cursor] original-row:num <- get *editor, cursor-row:offset - editor, scroll?:bool <- move-cursor-coordinates-left editor + scroll?:bool <- move-cursor-coordinates-left editor backspaced-cell:&:duplex-list:char <- copy before-cursor data <- remove before-cursor, data # will also neatly trim next/prev pointers in backspaced-cell/before-cursor before-cursor <- copy prev *editor <- put *editor, before-cursor:offset, before-cursor - go-render? <- copy 1/true - return-if scroll? + return-if scroll?, 1/go-render screen-width:num <- screen-width screen cursor-row:num <- get *editor, cursor-row:offset cursor-column:num <- get *editor, cursor-column:offset # did we just backspace over a newline? same-row?:bool <- equal cursor-row, original-row - go-render? <- copy 1/true - return-unless same-row? + return-unless same-row?, 1/go-render left:num <- get *editor, left:offset right:num <- get *editor, right:offset curr:&:duplex-list:char <- next before-cursor @@ -114,8 +110,7 @@ def delete-before-cursor editor:&:editor, screen:&:screen -> editor:&:editor, sc { # hit right margin? give up and let caller render at-right?:bool <- greater-or-equal curr-column, right - go-render? <- copy 1/true - return-if at-right? + return-if at-right?, 1/go-render break-unless curr # newline? done. currc:char <- get *curr, value:offset @@ -132,9 +127,10 @@ def delete-before-cursor editor:&:editor, screen:&:screen -> editor:&:editor, sc go-render? <- copy 0/false ] -def move-cursor-coordinates-left editor:&:editor -> editor:&:editor, go-render?:bool [ +def move-cursor-coordinates-left editor:&:editor -> go-render?:bool, editor:&:editor [ local-scope load-ingredients + go-render?:bool <- copy 0/false before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset cursor-row:num <- get *editor, cursor-row:offset cursor-column:num <- get *editor, cursor-column:offset @@ -146,12 +142,10 @@ def move-cursor-coordinates-left editor:&:editor -> editor:&:editor, go-render?: trace 10, [app], [decrementing cursor column] cursor-column <- subtract cursor-column, 1 *editor <- put *editor, cursor-column:offset, cursor-column - go-render? <- copy 0/false return } # if at left margin, we must move to previous row: top-of-screen?:bool <- equal cursor-row, 1 # exclude menu bar - go-render?:bool <- copy 0/false { break-if top-of-screen? cursor-row <- subtract cursor-row, 1 @@ -345,25 +339,23 @@ after <handle-special-key> [ delete-next-character?:bool <- equal k, 65522/delete break-unless delete-next-character? <delete-character-begin> - editor, screen, go-render?:bool, deleted-cell:&:duplex-list:char <- delete-at-cursor editor, screen + go-render?:bool, deleted-cell:&:duplex-list:char <- delete-at-cursor editor, screen <delete-character-end> return } ] -def delete-at-cursor editor:&:editor, screen:&:screen -> editor:&:editor, screen:&:screen, go-render?:bool, deleted-cell:&:duplex-list:char [ +def delete-at-cursor editor:&:editor, screen:&:screen -> go-render?:bool, deleted-cell:&:duplex-list:char, editor:&:editor, screen:&:screen [ local-scope load-ingredients before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset data:&:duplex-list:char <- get *editor, data:offset deleted-cell:&:duplex-list:char <- next before-cursor - go-render? <- copy 0/false - return-unless deleted-cell + return-unless deleted-cell, 0/don't-render currc:char <- get *deleted-cell, value:offset data <- remove deleted-cell, data deleted-newline?:bool <- equal currc, 10/newline - go-render? <- copy 1/true - return-if deleted-newline? + return-if deleted-newline?, 1/go-render # wasn't a newline? render rest of line curr:&:duplex-list:char <- next before-cursor # refresh after remove above cursor-row:num <- get *editor, cursor-row:offset @@ -374,8 +366,7 @@ def delete-at-cursor editor:&:editor, screen:&:screen -> editor:&:editor, screen { # hit right margin? give up and let caller render at-right?:bool <- greater-or-equal curr-column, screen-width - go-render? <- copy 1/true - return-if at-right? + return-if at-right?, 1/go-render break-unless curr # newline? done. currc:char <- get *curr, value:offset @@ -427,7 +418,7 @@ after <handle-special-key> [ <move-cursor-begin> before-cursor <- copy next-cursor *editor <- put *editor, before-cursor:offset, before-cursor - editor, go-render?:bool <- move-cursor-coordinates-right editor, screen-height + go-render?:bool <- move-cursor-coordinates-right editor, screen-height screen <- move-cursor screen, cursor-row, cursor-column undo-coalesce-tag:num <- copy 2/right-arrow <move-cursor-end> @@ -435,7 +426,7 @@ after <handle-special-key> [ } ] -def move-cursor-coordinates-right editor:&:editor, screen-height:num -> editor:&:editor, go-render?:bool [ +def move-cursor-coordinates-right editor:&:editor, screen-height:num -> go-render?:bool, editor:&:editor [ local-scope load-ingredients before-cursor:&:duplex-list:char <- get *editor before-cursor:offset @@ -453,13 +444,11 @@ def move-cursor-coordinates-right editor:&:editor, screen-height:num -> editor:& cursor-column <- copy left *editor <- put *editor, cursor-column:offset, cursor-column below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal - go-render? <- copy 0/false - return-unless below-screen? + return-unless below-screen?, 0/don't-render <scroll-down> cursor-row <- subtract cursor-row, 1 # bring back into screen range *editor <- put *editor, cursor-row:offset, cursor-row - go-render? <- copy 1/true - return + return 1/go-render } # if the line wraps, move cursor to start of next row { @@ -478,12 +467,11 @@ def move-cursor-coordinates-right editor:&:editor, screen-height:num -> editor:& cursor-column <- copy left *editor <- put *editor, cursor-column:offset, cursor-column below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal - return-unless below-screen?, editor, 0/no-more-render + return-unless below-screen?, 0/no-more-render <scroll-down> cursor-row <- subtract cursor-row, 1 # bring back into screen range *editor <- put *editor, cursor-row:offset, cursor-row - go-render? <- copy 1/true - return + return 1/go-render } # otherwise move cursor one character right cursor-column <- add cursor-column, 1 @@ -710,10 +698,9 @@ after <handle-special-key> [ trace 10, [app], [left arrow] # if not at start of text (before-cursor at § sentinel) prev:&:duplex-list:char <- prev before-cursor - go-render? <- copy 0/false - return-unless prev + return-unless prev, 0/don't-render <move-cursor-begin> - editor, go-render? <- move-cursor-coordinates-left editor + go-render? <- move-cursor-coordinates-left editor before-cursor <- copy prev *editor <- put *editor, before-cursor:offset, before-cursor undo-coalesce-tag:num <- copy 1/left-arrow @@ -979,16 +966,17 @@ after <handle-special-key> [ move-to-previous-line?:bool <- equal k, 65517/up-arrow break-unless move-to-previous-line? <move-cursor-begin> - editor, go-render? <- move-to-previous-line editor + go-render? <- move-to-previous-line editor undo-coalesce-tag:num <- copy 3/up-arrow <move-cursor-end> return } ] -def move-to-previous-line editor:&:editor -> editor:&:editor, go-render?:bool [ +def move-to-previous-line editor:&:editor -> go-render?:bool, editor:&:editor [ local-scope load-ingredients + go-render?:bool <- copy 0/false cursor-row:num <- get *editor, cursor-row:offset cursor-column:num <- get *editor, cursor-column:offset before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset @@ -1009,14 +997,12 @@ def move-to-previous-line editor:&:editor -> editor:&:editor, go-render?:bool [ break-if at-newline? curr:&:duplex-list:char <- before-previous-line curr, editor no-motion?:bool <- equal curr, old - go-render? <- copy 0/false return-if no-motion? } { old <- copy curr curr <- before-previous-line curr, editor no-motion?:bool <- equal curr, old - go-render? <- copy 0/false return-if no-motion? } before-cursor <- copy curr @@ -1042,15 +1028,13 @@ def move-to-previous-line editor:&:editor -> editor:&:editor, go-render?:bool [ *editor <- put *editor, cursor-column:offset, cursor-column loop } - go-render? <- copy 0/false return } { # if cursor already at top, scroll up break-unless already-at-top? <scroll-up> - go-render? <- copy 1/true - return + return 1/go-render } ] @@ -1213,14 +1197,14 @@ after <handle-special-key> [ move-to-next-line?:bool <- equal k, 65516/down-arrow break-unless move-to-next-line? <move-cursor-begin> - editor, go-render? <- move-to-next-line editor, screen-height + go-render? <- move-to-next-line editor, screen-height undo-coalesce-tag:num <- copy 4/down-arrow <move-cursor-end> return } ] -def move-to-next-line editor:&:editor, screen-height:num -> editor:&:editor, go-render?:bool [ +def move-to-next-line editor:&:editor, screen-height:num -> go-render?:bool, editor:&:editor [ local-scope load-ingredients cursor-row:num <- get *editor, cursor-row:offset @@ -1243,8 +1227,7 @@ def move-to-next-line editor:&:editor, screen-height:num -> editor:&:editor, go- break-unless no-motion? scroll?:bool <- greater-than cursor-row, 1 break-if scroll?, +try-to-scroll - go-render? <- copy 0/false - return + return 0/don't-render } cursor-row <- add cursor-row, 1 *editor <- put *editor, cursor-row:offset, cursor-row @@ -1268,8 +1251,7 @@ def move-to-next-line editor:&:editor, screen-height:num -> editor:&:editor, go- *editor <- put *editor, cursor-column:offset, cursor-column loop } - go-render? <- copy 0/false - return + return 0/don't-render } +try-to-scroll <scroll-down> @@ -1349,8 +1331,7 @@ after <handle-special-character> [ move-to-start-of-line editor undo-coalesce-tag:num <- copy 0/never <move-cursor-end> - go-render? <- copy 0/false - return + return 0/don't-render } ] @@ -1362,8 +1343,7 @@ after <handle-special-key> [ move-to-start-of-line editor undo-coalesce-tag:num <- copy 0/never <move-cursor-end> - go-render? <- copy 0/false - return + return 0/don't-render } ] @@ -1525,8 +1505,7 @@ after <handle-special-character> [ move-to-end-of-line editor undo-coalesce-tag:num <- copy 0/never <move-cursor-end> - go-render? <- copy 0/false - return + return 0/don't-render } ] @@ -1538,8 +1517,7 @@ after <handle-special-key> [ move-to-end-of-line editor undo-coalesce-tag:num <- copy 0/never <move-cursor-end> - go-render? <- copy 0/false - return + return 0/don't-render } ] @@ -1674,8 +1652,7 @@ after <handle-special-character> [ <delete-to-start-of-line-begin> deleted-cells:&:duplex-list:char <- delete-to-start-of-line editor <delete-to-start-of-line-end> - go-render? <- copy 1/true - return + return 1/go-render } ] @@ -1812,8 +1789,7 @@ after <handle-special-character> [ <delete-to-end-of-line-begin> deleted-cells:&:duplex-list:char <- delete-to-end-of-line editor <delete-to-end-of-line-end> - go-render? <- copy 1/true - return + return 1/go-render } ] @@ -2003,8 +1979,7 @@ after <scroll-down> [ top-of-screen <- before-start-of-next-line top-of-screen, max *editor <- put *editor, top-of-screen:offset, top-of-screen no-movement?:bool <- equal old-top, top-of-screen - go-render? <- copy 0/false - return-if no-movement? + return-if no-movement?, 0/don't-render ] # takes a pointer into the doubly-linked list, scans ahead at most 'max' @@ -2383,8 +2358,7 @@ after <scroll-up> [ top-of-screen <- before-previous-line top-of-screen, editor *editor <- put *editor, top-of-screen:offset, top-of-screen no-movement?:bool <- equal old-top, top-of-screen - go-render? <- copy 0/false - return-if no-movement? + return-if no-movement?, 0/don't-render ] # takes a pointer into the doubly-linked list, scans back to before start of @@ -2790,9 +2764,8 @@ after <handle-special-character> [ undo-coalesce-tag:num <- copy 0/never <move-cursor-end> top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset - no-movement?:bool <- equal top-of-screen, old-top - go-render? <- not no-movement? - return + movement?:bool <- not-equal top-of-screen, old-top + return movement?/go-render } ] @@ -2806,9 +2779,8 @@ after <handle-special-key> [ undo-coalesce-tag:num <- copy 0/never <move-cursor-end> top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset - no-movement?:bool <- equal top-of-screen, old-top - go-render? <- not no-movement? - return + movement?:bool <- not-equal top-of-screen, old-top + return movement?/go-render } ] @@ -2991,9 +2963,8 @@ after <handle-special-character> [ undo-coalesce-tag:num <- copy 0/never <move-cursor-end> top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset - no-movement?:bool <- equal top-of-screen, old-top - go-render? <- not no-movement? - return + movement?:bool <- not-equal top-of-screen, old-top + return movement?/go-render } ] @@ -3007,10 +2978,9 @@ after <handle-special-key> [ undo-coalesce-tag:num <- copy 0/never <move-cursor-end> top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset - no-movement?:bool <- equal top-of-screen, old-top + movement?:bool <- not-equal top-of-screen, old-top # don't bother re-rendering if nothing changed. todo: test this - go-render? <- not no-movement? - return + return movement?/go-render } ] diff --git a/edit/004-programming-environment.mu b/edit/004-programming-environment.mu index 7747e7a1..332b7e18 100644 --- a/edit/004-programming-environment.mu +++ b/edit/004-programming-environment.mu @@ -112,7 +112,7 @@ def event-loop screen:&:screen, console:&:console, env:&:environment -> screen:& sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset { break-if sandbox-in-focus? - screen, recipes, render?:bool <- handle-keyboard-event screen, recipes, e:event + render?:bool <- handle-keyboard-event screen, recipes, e:event # refresh screen only if no more events # if there are more events to process, wait for them to clear up, then make sure you render-all afterward. more-events?:bool <- has-more-events? console @@ -140,7 +140,7 @@ def event-loop screen:&:screen, console:&:console, env:&:environment -> screen:& } { break-unless sandbox-in-focus? - screen, current-sandbox, render?:bool <- handle-keyboard-event screen, current-sandbox, e:event + render?:bool <- handle-keyboard-event screen, current-sandbox, e:event # refresh screen only if no more events # if there are more events to process, wait for them to clear up, then make sure you render-all afterward. more-events?:bool <- has-more-events? console diff --git a/edit/012-editor-undo.mu b/edit/012-editor-undo.mu index c69e6c82..c2f6bca3 100644 --- a/edit/012-editor-undo.mu +++ b/edit/012-editor-undo.mu @@ -74,7 +74,7 @@ after <handle-special-character> [ redo <- push op, redo *editor <- put *editor, redo:offset, redo <handle-undo> - return screen, editor, 1/go-render + return 1/go-render } ] @@ -92,7 +92,7 @@ after <handle-special-character> [ undo <- push op, undo *editor <- put *editor, undo:offset, undo <handle-redo> - return screen, editor, 1/go-render + return 1/go-render } ] diff --git a/html/edit/002-typing.mu.html b/html/edit/002-typing.mu.html index 2c52331c..15853c1f 100644 --- a/html/edit/002-typing.mu.html +++ b/html/edit/002-typing.mu.html @@ -69,7 +69,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># keyboard events</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> is-touch? - screen, editor, go-render?:bool <span class="Special"><-</span> handle-keyboard-event screen, editor, e + go-render?:bool <span class="Special"><-</span> handle-keyboard-event screen, editor, e <span class="Delimiter">{</span> <span class="muControl">break-unless</span> go-render? screen <span class="Special"><-</span> editor-render screen, editor @@ -196,11 +196,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># Process an event 'e' and try to minimally update the screen.</span> <span class="Comment"># Set 'go-render?' to true to indicate the caller must perform a non-minimal update.</span> -<span class="muRecipe">def</span> handle-keyboard-event screen:&:screen, editor:&:editor, e:event<span class="muRecipe"> -> </span>screen:&:screen, editor:&:editor, go-render?:bool [ +<span class="muRecipe">def</span> handle-keyboard-event screen:&:screen, editor:&:editor, e:event<span class="muRecipe"> -> </span>go-render?:bool, screen:&:screen, editor:&:editor [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> - <span class="muControl">return-unless</span> editor + <span class="muControl">return-unless</span> editor, <span class="Constant">0/don't-render</span> screen-width:num <span class="Special"><-</span> screen-width screen screen-height:num <span class="Special"><-</span> screen-height screen left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> @@ -219,11 +218,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> <handle-special-character></span> <span class="Comment"># ignore any other special characters</span> regular-character?:bool <span class="Special"><-</span> greater-or-equal c, <span class="Constant">32/space</span> - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> - <span class="muControl">return-unless</span> regular-character? + <span class="muControl">return-unless</span> regular-character?, <span class="Constant">0/don't-render</span> <span class="Comment"># otherwise type it in</span> <span class="Constant"> <insert-character-begin></span> - editor, screen, go-render?:bool <span class="Special"><-</span> insert-at-cursor editor, c, screen + go-render? <span class="Special"><-</span> insert-at-cursor editor, c, screen <span class="Constant"> <insert-character-end></span> <span class="muControl">return</span> <span class="Delimiter">}</span> @@ -232,11 +230,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color assert is-keycode?, <span class="Constant">[event was of unknown type; neither keyboard nor mouse]</span> <span class="Comment"># handlers for each special key will go here</span> <span class="Constant"> <handle-special-key></span> - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">1/go-render</span> ] -<span class="muRecipe">def</span> insert-at-cursor editor:&:editor, c:char, screen:&:screen<span class="muRecipe"> -> </span>editor:&:editor, screen:&:screen, go-render?:bool [ +<span class="muRecipe">def</span> insert-at-cursor editor:&:editor, c:char, screen:&:screen<span class="muRecipe"> -> </span>go-render?:bool, editor:&:editor, screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> @@ -268,8 +265,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muControl">break-if</span> overflow? move-cursor screen, save-row, save-column print screen, c - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">0/don't-render</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="Comment"># not at right margin? print the character and rest of line</span> @@ -281,9 +277,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color curr-column:num <span class="Special"><-</span> copy save-column <span class="Delimiter">{</span> <span class="Comment"># hit right margin? give up and let caller render</span> - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> at-right?:bool <span class="Special"><-</span> greater-than curr-column, right - <span class="muControl">return-if</span> at-right? + <span class="muControl">return-if</span> at-right?, <span class="Constant">1/go-render</span> <span class="muControl">break-unless</span> curr <span class="Comment"># newline? done.</span> currc:char <span class="Special"><-</span> get *curr, <span class="Constant">value:offset</span> @@ -294,11 +289,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color curr <span class="Special"><-</span> next curr <span class="muControl">loop</span> <span class="Delimiter">}</span> - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">0/don't-render</span> <span class="Delimiter">}</span> - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">1/go-render</span> ] <span class="Comment"># helper for tests</span> @@ -775,8 +768,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muControl">break-unless</span> below-screen? <span class="Constant"> <scroll-down></span> <span class="Delimiter">}</span> - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">1/go-render</span> <span class="Delimiter">}</span> ] @@ -898,14 +890,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color newline?:bool <span class="Special"><-</span> equal c, <span class="Constant">10/newline</span> <span class="muControl">break-unless</span> newline? <span class="Constant"> <insert-enter-begin></span> - editor <span class="Special"><-</span> insert-new-line-and-indent editor, screen + insert-new-line-and-indent editor, screen <span class="Constant"> <insert-enter-end></span> - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">1/go-render</span> <span class="Delimiter">}</span> ] -<span class="muRecipe">def</span> insert-new-line-and-indent editor:&:editor, screen:&:screen<span class="muRecipe"> -> </span>editor:&:editor, screen:&:screen, go-render?:bool [ +<span class="muRecipe">def</span> insert-new-line-and-indent editor:&:editor, screen:&:screen<span class="muRecipe"> -> </span>editor:&:editor, screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> @@ -927,7 +918,6 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color below-screen?:bool <span class="Special"><-</span> greater-or-equal cursor-row, screen-height <span class="Comment"># must be equal, never greater</span> <span class="muControl">break-unless</span> below-screen? <span class="Constant"> <scroll-down></span> - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> cursor-row <span class="Special"><-</span> subtract cursor-row,<span class="Constant"> 1</span> <span class="Comment"># bring back into screen range</span> *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row <span class="Delimiter">}</span> @@ -941,7 +931,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Delimiter">{</span> indent-done?:bool <span class="Special"><-</span> greater-or-equal i, indent <span class="muControl">break-if</span> indent-done? - editor, screen, go-render?:bool <span class="Special"><-</span> insert-at-cursor editor, <span class="Constant">32/space</span>, screen + insert-at-cursor editor, <span class="Constant">32/space</span>, screen i <span class="Special"><-</span> add i,<span class="Constant"> 1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> @@ -1083,8 +1073,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color paste-start?:bool <span class="Special"><-</span> equal k, <span class="Constant">65507/paste-start</span> <span class="muControl">break-unless</span> paste-start? *editor <span class="Special"><-</span> put *editor, <span class="Constant">indent?:offset</span>, <span class="Constant">0/false</span> - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">1/go-render</span> <span class="Delimiter">}</span> ] @@ -1093,8 +1082,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color paste-end?:bool <span class="Special"><-</span> equal k, <span class="Constant">65506/paste-end</span> <span class="muControl">break-unless</span> paste-end? *editor <span class="Special"><-</span> put *editor, <span class="Constant">indent?:offset</span>, <span class="Constant">1/true</span> - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">1/go-render</span> <span class="Delimiter">}</span> ] diff --git a/html/edit/003-shortcuts.mu.html b/html/edit/003-shortcuts.mu.html index 9225ac1a..e7b49f49 100644 --- a/html/edit/003-shortcuts.mu.html +++ b/html/edit/003-shortcuts.mu.html @@ -63,11 +63,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color tab?:bool <span class="Special"><-</span> equal c, <span class="Constant">9/tab</span> <span class="muControl">break-unless</span> tab? <span class="Constant"> <insert-character-begin></span> - editor, screen, go-render?:bool <span class="Special"><-</span> insert-at-cursor editor, <span class="Constant">32/space</span>, screen - editor, screen, go-render?:bool <span class="Special"><-</span> insert-at-cursor editor, <span class="Constant">32/space</span>, screen + insert-at-cursor editor, <span class="Constant">32/space</span>, screen + insert-at-cursor editor, <span class="Constant">32/space</span>, screen <span class="Constant"> <insert-character-end></span> - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">1/go-render</span> <span class="Delimiter">}</span> ] @@ -106,7 +105,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color delete-previous-character?:bool <span class="Special"><-</span> equal c, <span class="Constant">8/backspace</span> <span class="muControl">break-unless</span> delete-previous-character? <span class="Constant"> <backspace-character-begin></span> - editor, screen, go-render?:bool, backspaced-cell:&:duplex-list:char <span class="Special"><-</span> delete-before-cursor editor, screen + go-render?:bool, backspaced-cell:&:duplex-list:char <span class="Special"><-</span> delete-before-cursor editor, screen <span class="Constant"> <backspace-character-end></span> <span class="muControl">return</span> <span class="Delimiter">}</span> @@ -115,31 +114,28 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment"># return values:</span> <span class="Comment"># go-render? - whether caller needs to update the screen</span> <span class="Comment"># backspaced-cell - value deleted (or 0 if nothing was deleted) so we can save it for undo, etc.</span> -<span class="muRecipe">def</span> delete-before-cursor editor:&:editor, screen:&:screen<span class="muRecipe"> -> </span>editor:&:editor, screen:&:screen, go-render?:bool, backspaced-cell:&:duplex-list:char [ +<span class="muRecipe">def</span> delete-before-cursor editor:&:editor, screen:&:screen<span class="muRecipe"> -> </span>go-render?:bool, backspaced-cell:&:duplex-list:char, editor:&:editor, screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> data:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">data:offset</span> <span class="Comment"># if at start of text (before-cursor at § sentinel), return</span> prev:&:duplex-list:char <span class="Special"><-</span> prev before-cursor - go-render?, backspaced-cell <span class="Special"><-</span> copy <span class="Constant">0/no-more-render</span>, <span class="Constant">0/nothing-deleted</span> - <span class="muControl">return-unless</span> prev + <span class="muControl">return-unless</span> prev, <span class="Constant">0/no-more-render</span>, <span class="Constant">0/nothing-deleted</span> trace<span class="Constant"> 10</span>, <span class="Constant">[app]</span>, <span class="Constant">[delete-before-cursor]</span> original-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> - editor, scroll?:bool <span class="Special"><-</span> move-cursor-coordinates-left editor + scroll?:bool <span class="Special"><-</span> move-cursor-coordinates-left editor backspaced-cell:&:duplex-list:char <span class="Special"><-</span> copy before-cursor data <span class="Special"><-</span> remove before-cursor, data <span class="Comment"># will also neatly trim next/prev pointers in backspaced-cell/before-cursor</span> before-cursor <span class="Special"><-</span> copy prev *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> - <span class="muControl">return-if</span> scroll? + <span class="muControl">return-if</span> scroll?, <span class="Constant">1/go-render</span> screen-width:num <span class="Special"><-</span> screen-width screen cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> <span class="Comment"># did we just backspace over a newline?</span> same-row?:bool <span class="Special"><-</span> equal cursor-row, original-row - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> - <span class="muControl">return-unless</span> same-row? + <span class="muControl">return-unless</span> same-row?, <span class="Constant">1/go-render</span> left:num <span class="Special"><-</span> get *editor, <span class="Constant">left:offset</span> right:num <span class="Special"><-</span> get *editor, <span class="Constant">right:offset</span> curr:&:duplex-list:char <span class="Special"><-</span> next before-cursor @@ -148,8 +144,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Delimiter">{</span> <span class="Comment"># hit right margin? give up and let caller render</span> at-right?:bool <span class="Special"><-</span> greater-or-equal curr-column, right - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> - <span class="muControl">return-if</span> at-right? + <span class="muControl">return-if</span> at-right?, <span class="Constant">1/go-render</span> <span class="muControl">break-unless</span> curr <span class="Comment"># newline? done.</span> currc:char <span class="Special"><-</span> get *curr, <span class="Constant">value:offset</span> @@ -166,9 +161,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> ] -<span class="muRecipe">def</span> move-cursor-coordinates-left editor:&:editor<span class="muRecipe"> -> </span>editor:&:editor, go-render?:bool [ +<span class="muRecipe">def</span> move-cursor-coordinates-left editor:&:editor<span class="muRecipe"> -> </span>go-render?:bool, editor:&:editor [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> + go-render?:bool <span class="Special"><-</span> copy <span class="Constant">0/false</span> before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> @@ -180,12 +176,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace<span class="Constant"> 10</span>, <span class="Constant">[app]</span>, <span class="Constant">[decrementing cursor column]</span> cursor-column <span class="Special"><-</span> subtract cursor-column,<span class="Constant"> 1</span> *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># if at left margin, we must move to previous row:</span> top-of-screen?:bool <span class="Special"><-</span> equal cursor-row,<span class="Constant"> 1</span> <span class="Comment"># exclude menu bar</span> - go-render?:bool <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> top-of-screen? cursor-row <span class="Special"><-</span> subtract cursor-row,<span class="Constant"> 1</span> @@ -379,25 +373,23 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color delete-next-character?:bool <span class="Special"><-</span> equal k, <span class="Constant">65522/delete</span> <span class="muControl">break-unless</span> delete-next-character? <span class="Constant"> <delete-character-begin></span> - editor, screen, go-render?:bool, deleted-cell:&:duplex-list:char <span class="Special"><-</span> delete-at-cursor editor, screen + go-render?:bool, deleted-cell:&:duplex-list:char <span class="Special"><-</span> delete-at-cursor editor, screen <span class="Constant"> <delete-character-end></span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] -<span class="muRecipe">def</span> delete-at-cursor editor:&:editor, screen:&:screen<span class="muRecipe"> -> </span>editor:&:editor, screen:&:screen, go-render?:bool, deleted-cell:&:duplex-list:char [ +<span class="muRecipe">def</span> delete-at-cursor editor:&:editor, screen:&:screen<span class="muRecipe"> -> </span>go-render?:bool, deleted-cell:&:duplex-list:char, editor:&:editor, screen:&:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> data:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">data:offset</span> deleted-cell:&:duplex-list:char <span class="Special"><-</span> next before-cursor - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> - <span class="muControl">return-unless</span> deleted-cell + <span class="muControl">return-unless</span> deleted-cell, <span class="Constant">0/don't-render</span> currc:char <span class="Special"><-</span> get *deleted-cell, <span class="Constant">value:offset</span> data <span class="Special"><-</span> remove deleted-cell, data deleted-newline?:bool <span class="Special"><-</span> equal currc, <span class="Constant">10/newline</span> - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> - <span class="muControl">return-if</span> deleted-newline? + <span class="muControl">return-if</span> deleted-newline?, <span class="Constant">1/go-render</span> <span class="Comment"># wasn't a newline? render rest of line</span> curr:&:duplex-list:char <span class="Special"><-</span> next before-cursor <span class="Comment"># refresh after remove above</span> cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> @@ -408,8 +400,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Delimiter">{</span> <span class="Comment"># hit right margin? give up and let caller render</span> at-right?:bool <span class="Special"><-</span> greater-or-equal curr-column, screen-width - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> - <span class="muControl">return-if</span> at-right? + <span class="muControl">return-if</span> at-right?, <span class="Constant">1/go-render</span> <span class="muControl">break-unless</span> curr <span class="Comment"># newline? done.</span> currc:char <span class="Special"><-</span> get *curr, <span class="Constant">value:offset</span> @@ -461,7 +452,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant"> <move-cursor-begin></span> before-cursor <span class="Special"><-</span> copy next-cursor *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor - editor, go-render?:bool <span class="Special"><-</span> move-cursor-coordinates-right editor, screen-height + go-render?:bool <span class="Special"><-</span> move-cursor-coordinates-right editor, screen-height screen <span class="Special"><-</span> move-cursor screen, cursor-row, cursor-column undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">2/right-arrow</span> <span class="Constant"> <move-cursor-end></span> @@ -469,7 +460,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Delimiter">}</span> ] -<span class="muRecipe">def</span> move-cursor-coordinates-right editor:&:editor, screen-height:num<span class="muRecipe"> -> </span>editor:&:editor, go-render?:bool [ +<span class="muRecipe">def</span> move-cursor-coordinates-right editor:&:editor, screen-height:num<span class="muRecipe"> -> </span>go-render?:bool, editor:&:editor [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor <span class="Constant">before-cursor:offset</span> @@ -487,13 +478,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color cursor-column <span class="Special"><-</span> copy left *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column below-screen?:bool <span class="Special"><-</span> greater-or-equal cursor-row, screen-height <span class="Comment"># must be equal</span> - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> - <span class="muControl">return-unless</span> below-screen? + <span class="muControl">return-unless</span> below-screen?, <span class="Constant">0/don't-render</span> <span class="Constant"> <scroll-down></span> cursor-row <span class="Special"><-</span> subtract cursor-row,<span class="Constant"> 1</span> <span class="Comment"># bring back into screen range</span> *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">1/go-render</span> <span class="Delimiter">}</span> <span class="Comment"># if the line wraps, move cursor to start of next row</span> <span class="Delimiter">{</span> @@ -512,12 +501,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color cursor-column <span class="Special"><-</span> copy left *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column below-screen?:bool <span class="Special"><-</span> greater-or-equal cursor-row, screen-height <span class="Comment"># must be equal</span> - <span class="muControl">return-unless</span> below-screen?, editor, <span class="Constant">0/no-more-render</span> + <span class="muControl">return-unless</span> below-screen?, <span class="Constant">0/no-more-render</span> <span class="Constant"> <scroll-down></span> cursor-row <span class="Special"><-</span> subtract cursor-row,<span class="Constant"> 1</span> <span class="Comment"># bring back into screen range</span> *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">1/go-render</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise move cursor one character right</span> cursor-column <span class="Special"><-</span> add cursor-column,<span class="Constant"> 1</span> @@ -744,10 +732,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace<span class="Constant"> 10</span>, <span class="Constant">[app]</span>, <span class="Constant">[left arrow]</span> <span class="Comment"># if not at start of text (before-cursor at § sentinel)</span> prev:&:duplex-list:char <span class="Special"><-</span> prev before-cursor - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> - <span class="muControl">return-unless</span> prev + <span class="muControl">return-unless</span> prev, <span class="Constant">0/don't-render</span> <span class="Constant"> <move-cursor-begin></span> - editor, go-render? <span class="Special"><-</span> move-cursor-coordinates-left editor + go-render? <span class="Special"><-</span> move-cursor-coordinates-left editor before-cursor <span class="Special"><-</span> copy prev *editor <span class="Special"><-</span> put *editor, <span class="Constant">before-cursor:offset</span>, before-cursor undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">1/left-arrow</span> @@ -1013,16 +1000,17 @@ d] move-to-previous-line?:bool <span class="Special"><-</span> equal k, <span class="Constant">65517/up-arrow</span> <span class="muControl">break-unless</span> move-to-previous-line? <span class="Constant"> <move-cursor-begin></span> - editor, go-render? <span class="Special"><-</span> move-to-previous-line editor + go-render? <span class="Special"><-</span> move-to-previous-line editor undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">3/up-arrow</span> <span class="Constant"> <move-cursor-end></span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] -<span class="muRecipe">def</span> move-to-previous-line editor:&:editor<span class="muRecipe"> -> </span>editor:&:editor, go-render?:bool [ +<span class="muRecipe">def</span> move-to-previous-line editor:&:editor<span class="muRecipe"> -> </span>go-render?:bool, editor:&:editor [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> + go-render?:bool <span class="Special"><-</span> copy <span class="Constant">0/false</span> cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> cursor-column:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-column:offset</span> before-cursor:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">before-cursor:offset</span> @@ -1043,14 +1031,12 @@ d] <span class="muControl">break-if</span> at-newline? curr:&:duplex-list:char <span class="Special"><-</span> before-previous-line curr, editor no-motion?:bool <span class="Special"><-</span> equal curr, old - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return-if</span> no-motion? <span class="Delimiter">}</span> <span class="Delimiter">{</span> old <span class="Special"><-</span> copy curr curr <span class="Special"><-</span> before-previous-line curr, editor no-motion?:bool <span class="Special"><-</span> equal curr, old - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return-if</span> no-motion? <span class="Delimiter">}</span> before-cursor <span class="Special"><-</span> copy curr @@ -1076,15 +1062,13 @@ d] *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column <span class="muControl">loop</span> <span class="Delimiter">}</span> - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="Comment"># if cursor already at top, scroll up</span> <span class="muControl">break-unless</span> already-at-top? <span class="Constant"> <scroll-up></span> - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">1/go-render</span> <span class="Delimiter">}</span> ] @@ -1247,14 +1231,14 @@ d] move-to-next-line?:bool <span class="Special"><-</span> equal k, <span class="Constant">65516/down-arrow</span> <span class="muControl">break-unless</span> move-to-next-line? <span class="Constant"> <move-cursor-begin></span> - editor, go-render? <span class="Special"><-</span> move-to-next-line editor, screen-height + go-render? <span class="Special"><-</span> move-to-next-line editor, screen-height undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">4/down-arrow</span> <span class="Constant"> <move-cursor-end></span> <span class="muControl">return</span> <span class="Delimiter">}</span> ] -<span class="muRecipe">def</span> move-to-next-line editor:&:editor, screen-height:num<span class="muRecipe"> -> </span>editor:&:editor, go-render?:bool [ +<span class="muRecipe">def</span> move-to-next-line editor:&:editor, screen-height:num<span class="muRecipe"> -> </span>go-render?:bool, editor:&:editor [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> cursor-row:num <span class="Special"><-</span> get *editor, <span class="Constant">cursor-row:offset</span> @@ -1277,8 +1261,7 @@ d] <span class="muControl">break-unless</span> no-motion? scroll?:bool <span class="Special"><-</span> greater-than cursor-row,<span class="Constant"> 1</span> <span class="muControl">break-if</span> scroll?, <span class="Constant">+try-to-scroll</span> - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">0/don't-render</span> <span class="Delimiter">}</span> cursor-row <span class="Special"><-</span> add cursor-row,<span class="Constant"> 1</span> *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-row:offset</span>, cursor-row @@ -1302,8 +1285,7 @@ d] *editor <span class="Special"><-</span> put *editor, <span class="Constant">cursor-column:offset</span>, cursor-column <span class="muControl">loop</span> <span class="Delimiter">}</span> - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">0/don't-render</span> <span class="Delimiter">}</span> <span class="Constant"> +try-to-scroll</span> <span class="Constant"> <scroll-down></span> @@ -1383,8 +1365,7 @@ d] move-to-start-of-line editor undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">0/never</span> <span class="Constant"> <move-cursor-end></span> - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">0/don't-render</span> <span class="Delimiter">}</span> ] @@ -1396,8 +1377,7 @@ d] move-to-start-of-line editor undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">0/never</span> <span class="Constant"> <move-cursor-end></span> - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">0/don't-render</span> <span class="Delimiter">}</span> ] @@ -1559,8 +1539,7 @@ d] move-to-end-of-line editor undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">0/never</span> <span class="Constant"> <move-cursor-end></span> - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">0/don't-render</span> <span class="Delimiter">}</span> ] @@ -1572,8 +1551,7 @@ d] move-to-end-of-line editor undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">0/never</span> <span class="Constant"> <move-cursor-end></span> - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">0/don't-render</span> <span class="Delimiter">}</span> ] @@ -1708,8 +1686,7 @@ d] <span class="Constant"> <delete-to-start-of-line-begin></span> deleted-cells:&:duplex-list:char <span class="Special"><-</span> delete-to-start-of-line editor <span class="Constant"> <delete-to-start-of-line-end></span> - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">1/go-render</span> <span class="Delimiter">}</span> ] @@ -1846,8 +1823,7 @@ d] <span class="Constant"> <delete-to-end-of-line-begin></span> deleted-cells:&:duplex-list:char <span class="Special"><-</span> delete-to-end-of-line editor <span class="Constant"> <delete-to-end-of-line-end></span> - go-render? <span class="Special"><-</span> copy <span class="Constant">1/true</span> - <span class="muControl">return</span> + <span class="muControl">return</span> <span class="Constant">1/go-render</span> <span class="Delimiter">}</span> ] @@ -2037,8 +2013,7 @@ d] top-of-screen <span class="Special"><-</span> before-start-of-next-line top-of-screen, max *editor <span class="Special"><-</span> put *editor, <span class="Constant">top-of-screen:offset</span>, top-of-screen no-movement?:bool <span class="Special"><-</span> equal old-top, top-of-screen - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> - <span class="muControl">return-if</span> no-movement? + <span class="muControl">return-if</span> no-movement?, <span class="Constant">0/don't-render</span> ] <span class="Comment"># takes a pointer into the doubly-linked list, scans ahead at most 'max'</span> @@ -2417,8 +2392,7 @@ d] top-of-screen <span class="Special"><-</span> before-previous-line top-of-screen, editor *editor <span class="Special"><-</span> put *editor, <span class="Constant">top-of-screen:offset</span>, top-of-screen no-movement?:bool <span class="Special"><-</span> equal old-top, top-of-screen - go-render? <span class="Special"><-</span> copy <span class="Constant">0/false</span> - <span class="muControl">return-if</span> no-movement? + <span class="muControl">return-if</span> no-movement?, <span class="Constant">0/don't-render</span> ] <span class="Comment"># takes a pointer into the doubly-linked list, scans back to before start of</span> @@ -2824,9 +2798,8 @@ e] undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">0/never</span> <span class="Constant"> <move-cursor-end></span> top-of-screen:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> - no-movement?:bool <span class="Special"><-</span> equal top-of-screen, old-top - go-render? <span class="Special"><-</span> not no-movement? - <span class="muControl">return</span> + movement?:bool <span class="Special"><-</span> not-equal top-of-screen, old-top + <span class="muControl">return</span> movement?/go-render <span class="Delimiter">}</span> ] @@ -2840,9 +2813,8 @@ e] undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">0/never</span> <span class="Constant"> <move-cursor-end></span> top-of-screen:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> - no-movement?:bool <span class="Special"><-</span> equal top-of-screen, old-top - go-render? <span class="Special"><-</span> not no-movement? - <span class="muControl">return</span> + movement?:bool <span class="Special"><-</span> not-equal top-of-screen, old-top + <span class="muControl">return</span> movement?/go-render <span class="Delimiter">}</span> ] @@ -3025,9 +2997,8 @@ e] undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">0/never</span> <span class="Constant"> <move-cursor-end></span> top-of-screen:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> - no-movement?:bool <span class="Special"><-</span> equal top-of-screen, old-top - go-render? <span class="Special"><-</span> not no-movement? - <span class="muControl">return</span> + movement?:bool <span class="Special"><-</span> not-equal top-of-screen, old-top + <span class="muControl">return</span> movement?/go-render <span class="Delimiter">}</span> ] @@ -3041,10 +3012,9 @@ e] undo-coalesce-tag:num <span class="Special"><-</span> copy <span class="Constant">0/never</span> <span class="Constant"> <move-cursor-end></span> top-of-screen:&:duplex-list:char <span class="Special"><-</span> get *editor, <span class="Constant">top-of-screen:offset</span> - no-movement?:bool <span class="Special"><-</span> equal top-of-screen, old-top + movement?:bool <span class="Special"><-</span> not-equal top-of-screen, old-top <span class="Comment"># don't bother re-rendering if nothing changed. todo: test this</span> - go-render? <span class="Special"><-</span> not no-movement? - <span class="muControl">return</span> + <span class="muControl">return</span> movement?/go-render <span class="Delimiter">}</span> ] diff --git a/html/edit/004-programming-environment.mu.html b/html/edit/004-programming-environment.mu.html index f363ac7e..776c336e 100644 --- a/html/edit/004-programming-environment.mu.html +++ b/html/edit/004-programming-environment.mu.html @@ -147,7 +147,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color sandbox-in-focus?:bool <span class="Special"><-</span> get *env, <span class="Constant">sandbox-in-focus?:offset</span> <span class="Delimiter">{</span> <span class="muControl">break-if</span> sandbox-in-focus? - screen, recipes, render?:bool <span class="Special"><-</span> handle-keyboard-event screen, recipes, e:event + render?:bool <span class="Special"><-</span> handle-keyboard-event screen, recipes, e:event <span class="Comment"># refresh screen only if no more events</span> <span class="Comment"># if there are more events to process, wait for them to clear up, then make sure you render-all afterward.</span> more-events?:bool <span class="Special"><-</span> has-more-events? console @@ -175,7 +175,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Delimiter">}</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> sandbox-in-focus? - screen, current-sandbox, render?:bool <span class="Special"><-</span> handle-keyboard-event screen, current-sandbox, e:event + render?:bool <span class="Special"><-</span> handle-keyboard-event screen, current-sandbox, e:event <span class="Comment"># refresh screen only if no more events</span> <span class="Comment"># if there are more events to process, wait for them to clear up, then make sure you render-all afterward.</span> more-events?:bool <span class="Special"><-</span> has-more-events? console diff --git a/html/edit/012-editor-undo.mu.html b/html/edit/012-editor-undo.mu.html index c0f6d84a..ec4fd7b9 100644 --- a/html/edit/012-editor-undo.mu.html +++ b/html/edit/012-editor-undo.mu.html @@ -109,7 +109,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color redo <span class="Special"><-</span> push op, redo *editor <span class="Special"><-</span> put *editor, <span class="Constant">redo:offset</span>, redo <span class="Constant"> <handle-undo></span> - <span class="muControl">return</span> screen, editor, <span class="Constant">1/go-render</span> + <span class="muControl">return</span> <span class="Constant">1/go-render</span> <span class="Delimiter">}</span> ] @@ -127,7 +127,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color undo <span class="Special"><-</span> push op, undo *editor <span class="Special"><-</span> put *editor, <span class="Constant">undo:offset</span>, undo <span class="Constant"> <handle-redo></span> - <span class="muControl">return</span> screen, editor, <span class="Constant">1/go-render</span> + <span class="muControl">return</span> <span class="Constant">1/go-render</span> <span class="Delimiter">}</span> ] diff --git a/sandbox/002-typing.mu b/sandbox/002-typing.mu index a584e6a3..4f704f0d 100644 --- a/sandbox/002-typing.mu +++ b/sandbox/002-typing.mu @@ -34,7 +34,7 @@ def editor-event-loop screen:&:screen, console:&:console, editor:&:editor -> scr # keyboard events { break-if is-touch? - screen, editor, go-render?:bool <- handle-keyboard-event screen, editor, e + go-render?:bool <- handle-keyboard-event screen, editor, e { break-unless go-render? screen <- editor-render screen, editor @@ -161,11 +161,10 @@ def snap-cursor screen:&:screen, editor:&:editor, target-row:num, target-column: # Process an event 'e' and try to minimally update the screen. # Set 'go-render?' to true to indicate the caller must perform a non-minimal update. -def handle-keyboard-event screen:&:screen, editor:&:editor, e:event -> screen:&:screen, editor:&:editor, go-render?:bool [ +def handle-keyboard-event screen:&:screen, editor:&:editor, e:event -> go-render?:bool, screen:&:screen, editor:&:editor [ local-scope load-ingredients - go-render? <- copy 0/false - return-unless editor + return-unless editor, 0/don't-render screen-width:num <- screen-width screen screen-height:num <- screen-height screen left:num <- get *editor, left:offset @@ -184,11 +183,10 @@ def handle-keyboard-event screen:&:screen, editor:&:editor, e:event -> screen:&: <handle-special-character> # ignore any other special characters regular-character?:bool <- greater-or-equal c, 32/space - go-render? <- copy 0/false - return-unless regular-character? + return-unless regular-character?, 0/don't-render # otherwise type it in <insert-character-begin> - editor, screen, go-render?:bool <- insert-at-cursor editor, c, screen + go-render? <- insert-at-cursor editor, c, screen <insert-character-end> return } @@ -197,11 +195,10 @@ def handle-keyboard-event screen:&:screen, editor:&:editor, e:event -> screen:&: assert is-keycode?, [event was of unknown type; neither keyboard nor mouse] # handlers for each special key will go here <handle-special-key> - go-render? <- copy 1/true - return + return 1/go-render ] -def insert-at-cursor editor:&:editor, c:char, screen:&:screen -> editor:&:editor, screen:&:screen, go-render?:bool [ +def insert-at-cursor editor:&:editor, c:char, screen:&:screen -> go-render?:bool, editor:&:editor, screen:&:screen [ local-scope load-ingredients before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset @@ -233,8 +230,7 @@ def insert-at-cursor editor:&:editor, c:char, screen:&:screen -> editor:&:editor break-if overflow? move-cursor screen, save-row, save-column print screen, c - go-render? <- copy 0/false - return + return 0/don't-render } { # not at right margin? print the character and rest of line @@ -246,9 +242,8 @@ def insert-at-cursor editor:&:editor, c:char, screen:&:screen -> editor:&:editor curr-column:num <- copy save-column { # hit right margin? give up and let caller render - go-render? <- copy 1/true at-right?:bool <- greater-than curr-column, right - return-if at-right? + return-if at-right?, 1/go-render break-unless curr # newline? done. currc:char <- get *curr, value:offset @@ -259,11 +254,9 @@ def insert-at-cursor editor:&:editor, c:char, screen:&:screen -> editor:&:editor curr <- next curr loop } - go-render? <- copy 0/false - return + return 0/don't-render } - go-render? <- copy 1/true - return + return 1/go-render ] # helper for tests @@ -740,8 +733,7 @@ after <insert-character-special-case> [ break-unless below-screen? <scroll-down> } - go-render? <- copy 1/true - return + return 1/go-render } ] @@ -863,14 +855,13 @@ after <handle-special-character> [ newline?:bool <- equal c, 10/newline break-unless newline? <insert-enter-begin> - editor <- insert-new-line-and-indent editor, screen + insert-new-line-and-indent editor, screen <insert-enter-end> - go-render? <- copy 1/true - return + return 1/go-render } ] -def insert-new-line-and-indent editor:&:editor, screen:&:screen -> editor:&:editor, screen:&:screen, go-render?:bool [ +def insert-new-line-and-indent editor:&:editor, screen:&:screen -> editor:&:editor, screen:&:screen [ local-scope load-ingredients cursor-row:num <- get *editor, cursor-row:offset @@ -892,7 +883,6 @@ def insert-new-line-and-indent editor:&:editor, screen:&:screen -> editor:&:edit below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal, never greater break-unless below-screen? <scroll-down> - go-render? <- copy 1/true cursor-row <- subtract cursor-row, 1 # bring back into screen range *editor <- put *editor, cursor-row:offset, cursor-row } @@ -906,7 +896,7 @@ def insert-new-line-and-indent editor:&:editor, screen:&:screen -> editor:&:edit { indent-done?:bool <- greater-or-equal i, indent break-if indent-done? - editor, screen, go-render?:bool <- insert-at-cursor editor, 32/space, screen + insert-at-cursor editor, 32/space, screen i <- add i, 1 loop } @@ -1048,8 +1038,7 @@ after <handle-special-key> [ paste-start?:bool <- equal k, 65507/paste-start break-unless paste-start? *editor <- put *editor, indent?:offset, 0/false - go-render? <- copy 1/true - return + return 1/go-render } ] @@ -1058,8 +1047,7 @@ after <handle-special-key> [ paste-end?:bool <- equal k, 65506/paste-end break-unless paste-end? *editor <- put *editor, indent?:offset, 1/true - go-render? <- copy 1/true - return + return 1/go-render } ] diff --git a/sandbox/003-shortcuts.mu b/sandbox/003-shortcuts.mu index d4255704..4ea2b8cd 100644 --- a/sandbox/003-shortcuts.mu +++ b/sandbox/003-shortcuts.mu @@ -29,11 +29,10 @@ after <handle-special-character> [ tab?:bool <- equal c, 9/tab break-unless tab? <insert-character-begin> - editor, screen, go-render?:bool <- insert-at-cursor editor, 32/space, screen - editor, screen, go-render?:bool <- insert-at-cursor editor, 32/space, screen + insert-at-cursor editor, 32/space, screen + insert-at-cursor editor, 32/space, screen <insert-character-end> - go-render? <- copy 1/true - return + return 1/go-render } ] @@ -72,7 +71,7 @@ after <handle-special-character> [ delete-previous-character?:bool <- equal c, 8/backspace break-unless delete-previous-character? <backspace-character-begin> - editor, screen, go-render?:bool, backspaced-cell:&:duplex-list:char <- delete-before-cursor editor, screen + go-render?:bool, backspaced-cell:&:duplex-list:char <- delete-before-cursor editor, screen <backspace-character-end> return } @@ -81,19 +80,17 @@ after <handle-special-character> [ # return values: # go-render? - whether caller needs to update the screen # backspaced-cell - value deleted (or 0 if nothing was deleted) so we can save it for undo, etc. -def delete-before-cursor editor:&:editor, screen:&:screen -> editor:&:editor, screen:&:screen, go-render?:bool, backspaced-cell:&:duplex-list:char [ +def delete-before-cursor editor:&:editor, screen:&:screen -> go-render?:bool, backspaced-cell:&:duplex-list:char, editor:&:editor, screen:&:screen [ local-scope load-ingredients before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset data:&:duplex-list:char <- get *editor, data:offset # if at start of text (before-cursor at § sentinel), return prev:&:duplex-list:char <- prev before-cursor - go-render?, backspaced-cell <- copy 0/no-more-render, 0/nothing-deleted - return-unless prev - go-render? <- copy 1/true + return-unless prev, 0/no-more-render, 0/nothing-deleted trace 10, [app], [delete-before-cursor] original-row:num <- get *editor, cursor-row:offset - editor <- move-cursor-coordinates-left editor + move-cursor-coordinates-left editor backspaced-cell:&:duplex-list:char <- copy before-cursor data <- remove before-cursor, data # will also neatly trim next/prev pointers in backspaced-cell/before-cursor before-cursor <- copy prev @@ -103,7 +100,7 @@ def delete-before-cursor editor:&:editor, screen:&:screen -> editor:&:editor, sc cursor-column:num <- get *editor, cursor-column:offset # did we just backspace over a newline? same-row?:bool <- equal cursor-row, original-row - return-unless same-row? + return-unless same-row?, 1/go-render left:num <- get *editor, left:offset right:num <- get *editor, right:offset curr:&:duplex-list:char <- next before-cursor @@ -112,7 +109,7 @@ def delete-before-cursor editor:&:editor, screen:&:screen -> editor:&:editor, sc { # hit right margin? give up and let caller render at-right?:bool <- greater-or-equal curr-column, right - return-if at-right? + return-if at-right?, 1/go-render break-unless curr # newline? done. currc:char <- get *curr, value:offset @@ -339,25 +336,23 @@ after <handle-special-key> [ delete-next-character?:bool <- equal k, 65522/delete break-unless delete-next-character? <delete-character-begin> - editor, screen, go-render?:bool, deleted-cell:&:duplex-list:char <- delete-at-cursor editor, screen + go-render?:bool, deleted-cell:&:duplex-list:char <- delete-at-cursor editor, screen <delete-character-end> return } ] -def delete-at-cursor editor:&:editor, screen:&:screen -> editor:&:editor, screen:&:screen, go-render?:bool, deleted-cell:&:duplex-list:char [ +def delete-at-cursor editor:&:editor, screen:&:screen -> go-render?:bool, deleted-cell:&:duplex-list:char, editor:&:editor, screen:&:screen [ local-scope load-ingredients before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset data:&:duplex-list:char <- get *editor, data:offset deleted-cell:&:duplex-list:char <- next before-cursor - go-render? <- copy 0/false - return-unless deleted-cell + return-unless deleted-cell, 0/don't-render currc:char <- get *deleted-cell, value:offset data <- remove deleted-cell, data deleted-newline?:bool <- equal currc, 10/newline - go-render? <- copy 1/true - return-if deleted-newline? + return-if deleted-newline?, 1/go-render # wasn't a newline? render rest of line curr:&:duplex-list:char <- next before-cursor # refresh after remove above cursor-row:num <- get *editor, cursor-row:offset @@ -368,8 +363,7 @@ def delete-at-cursor editor:&:editor, screen:&:screen -> editor:&:editor, screen { # hit right margin? give up and let caller render at-right?:bool <- greater-or-equal curr-column, screen-width - go-render? <- copy 1/true - return-if at-right? + return-if at-right?, 1/go-render break-unless curr # newline? done. currc:char <- get *curr, value:offset @@ -421,7 +415,7 @@ after <handle-special-key> [ <move-cursor-begin> before-cursor <- copy next-cursor *editor <- put *editor, before-cursor:offset, before-cursor - editor, go-render?:bool <- move-cursor-coordinates-right editor, screen-height + go-render?:bool <- move-cursor-coordinates-right editor, screen-height screen <- move-cursor screen, cursor-row, cursor-column undo-coalesce-tag:num <- copy 2/right-arrow <move-cursor-end> @@ -429,7 +423,7 @@ after <handle-special-key> [ } ] -def move-cursor-coordinates-right editor:&:editor, screen-height:num -> editor:&:editor, go-render?:bool [ +def move-cursor-coordinates-right editor:&:editor, screen-height:num -> go-render?:bool, editor:&:editor [ local-scope load-ingredients before-cursor:&:duplex-list:char <- get *editor before-cursor:offset @@ -447,12 +441,10 @@ def move-cursor-coordinates-right editor:&:editor, screen-height:num -> editor:& cursor-column <- copy left *editor <- put *editor, cursor-column:offset, cursor-column below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal - go-render? <- copy 0/false - return-unless below-screen? + return-unless below-screen?, 0/don't-render cursor-row <- subtract cursor-row, 1 # bring back into screen range *editor <- put *editor, cursor-row:offset, cursor-row - go-render? <- copy 1/true - return + return 1/go-render } # if the line wraps, move cursor to start of next row { @@ -471,11 +463,10 @@ def move-cursor-coordinates-right editor:&:editor, screen-height:num -> editor:& cursor-column <- copy left *editor <- put *editor, cursor-column:offset, cursor-column below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal - return-unless below-screen?, editor, 0/no-more-render + return-unless below-screen?, 0/no-more-render cursor-row <- subtract cursor-row, 1 # bring back into screen range *editor <- put *editor, cursor-row:offset, cursor-row - go-render? <- copy 1/true - return + return 1/go-render } # otherwise move cursor one character right cursor-column <- add cursor-column, 1 @@ -702,10 +693,9 @@ after <handle-special-key> [ trace 10, [app], [left arrow] # if not at start of text (before-cursor at § sentinel) prev:&:duplex-list:char <- prev before-cursor - go-render? <- copy 0/false - return-unless prev + return-unless prev, 0/don't-render <move-cursor-begin> - editor <- move-cursor-coordinates-left editor + move-cursor-coordinates-left editor before-cursor <- copy prev *editor <- put *editor, before-cursor:offset, before-cursor undo-coalesce-tag:num <- copy 1/left-arrow @@ -971,14 +961,14 @@ after <handle-special-key> [ move-to-previous-line?:bool <- equal k, 65517/up-arrow break-unless move-to-previous-line? <move-cursor-begin> - editor, go-render? <- move-to-previous-line editor + move-to-previous-line editor undo-coalesce-tag:num <- copy 3/up-arrow <move-cursor-end> return } ] -def move-to-previous-line editor:&:editor -> editor:&:editor, go-render?:bool [ +def move-to-previous-line editor:&:editor -> editor:&:editor [ local-scope load-ingredients cursor-row:num <- get *editor, cursor-row:offset @@ -1001,14 +991,12 @@ def move-to-previous-line editor:&:editor -> editor:&:editor, go-render?:bool [ break-if at-newline? curr:&:duplex-list:char <- before-previous-line curr, editor no-motion?:bool <- equal curr, old - go-render? <- copy 0/false return-if no-motion? } { old <- copy curr curr <- before-previous-line curr, editor no-motion?:bool <- equal curr, old - go-render? <- copy 0/false return-if no-motion? } before-cursor <- copy curr @@ -1034,14 +1022,6 @@ def move-to-previous-line editor:&:editor -> editor:&:editor, go-render?:bool [ *editor <- put *editor, cursor-column:offset, cursor-column loop } - go-render? <- copy 0/false - return - } - { - # if cursor already at top, do nothing - break-unless already-at-top? - go-render? <- copy 0/true - return } ] @@ -1326,8 +1306,7 @@ after <handle-special-character> [ move-to-start-of-line editor undo-coalesce-tag:num <- copy 0/never <move-cursor-end> - go-render? <- copy 0/false - return + return 0/don't-render } ] @@ -1339,8 +1318,7 @@ after <handle-special-key> [ move-to-start-of-line editor undo-coalesce-tag:num <- copy 0/never <move-cursor-end> - go-render? <- copy 0/false - return + return 0/don't-render } ] @@ -1502,8 +1480,7 @@ after <handle-special-character> [ move-to-end-of-line editor undo-coalesce-tag:num <- copy 0/never <move-cursor-end> - go-render? <- copy 0/false - return + return 0/don't-render } ] @@ -1515,8 +1492,7 @@ after <handle-special-key> [ move-to-end-of-line editor undo-coalesce-tag:num <- copy 0/never <move-cursor-end> - go-render? <- copy 0/false - return + return 0/don't-render } ] @@ -1651,8 +1627,7 @@ after <handle-special-character> [ <delete-to-start-of-line-begin> deleted-cells:&:duplex-list:char <- delete-to-start-of-line editor <delete-to-start-of-line-end> - go-render? <- copy 1/true - return + return 1/go-render } ] @@ -1789,8 +1764,7 @@ after <handle-special-character> [ <delete-to-end-of-line-begin> deleted-cells:&:duplex-list:char <- delete-to-end-of-line editor <delete-to-end-of-line-end> - go-render? <- copy 1/true - return + return 1/go-render } ] diff --git a/sandbox/004-programming-environment.mu b/sandbox/004-programming-environment.mu index c32501a6..84898f71 100644 --- a/sandbox/004-programming-environment.mu +++ b/sandbox/004-programming-environment.mu @@ -104,7 +104,7 @@ def event-loop screen:&:screen, console:&:console, env:&:environment -> screen:& # if it's not global and not a touch event, send to appropriate editor { hide-screen screen - screen, current-sandbox, render?:bool <- handle-keyboard-event screen, current-sandbox, e:event + render?:bool <- handle-keyboard-event screen, current-sandbox, e:event # refresh screen only if no more events # if there are more events to process, wait for them to clear up, then make sure you render-all afterward. more-events?:bool <- has-more-events? console diff --git a/sandbox/012-editor-undo.mu b/sandbox/012-editor-undo.mu index a3e4956d..bf64cd75 100644 --- a/sandbox/012-editor-undo.mu +++ b/sandbox/012-editor-undo.mu @@ -74,7 +74,7 @@ after <handle-special-character> [ redo <- push op, redo *editor <- put *editor, redo:offset, redo <handle-undo> - return screen, editor, 1/go-render + return 1/go-render } ] @@ -92,7 +92,7 @@ after <handle-special-character> [ undo <- push op, undo *editor <- put *editor, undo:offset, undo <handle-redo> - return screen, editor, 1/go-render + return 1/go-render } ] |