diff options
Diffstat (limited to 'sandbox/003-shortcuts.mu')
-rw-r--r-- | sandbox/003-shortcuts.mu | 86 |
1 files changed, 30 insertions, 56 deletions
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 } ] |