diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2017-06-09 15:54:26 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2017-06-09 15:54:26 -0700 |
commit | bd5d3936ec77e0ec42d6f9d99d377d807e9892f8 (patch) | |
tree | 1ed27754e58d345070ef5cb5ee7404592bf31d7a /edit | |
parent | 6d12a8c4ebe25527c92a934702e2628ce8c4bd4c (diff) | |
download | mu-bd5d3936ec77e0ec42d6f9d99d377d807e9892f8.tar.gz |
3903 - minimal render when pressing 'tab'
Turns out all I had to do was reset `go-render?` to false.
Diffstat (limited to 'edit')
-rw-r--r-- | edit/003-shortcuts.mu | 54 |
1 files changed, 39 insertions, 15 deletions
diff --git a/edit/003-shortcuts.mu b/edit/003-shortcuts.mu index f2cc26af..1fbb620f 100644 --- a/edit/003-shortcuts.mu +++ b/edit/003-shortcuts.mu @@ -10,6 +10,8 @@ scenario editor-inserts-two-spaces-on-tab [ s:text <- new [ab cd] e:&:editor <- new-editor s, 0/left, 5/right + render screen, e + $clear-trace assume-console [ press tab ] @@ -21,6 +23,30 @@ cd] . ab . .cd . ] + # we render at most two editor rows worth (one row for each space) + check-trace-count-for-label-lesser-than 10, [print-character] +] + +scenario editor-inserts-two-spaces-and-wraps-line-on-tab [ + local-scope + assume-screen 10/width, 5/height + s:text <- new [abcd] + e:&:editor <- new-editor s, 0/left, 5/right + render screen, e + $clear-trace + assume-console [ + press tab + ] + run [ + editor-event-loop screen, console, e + ] + screen-should-contain [ + . . + . ab↩ . + .cd . + ] + # we re-render the whole editor + check-trace-count-for-label-greater-than 10, [print-character] ] after <handle-special-character> [ @@ -28,10 +54,12 @@ after <handle-special-character> [ tab?:bool <- equal c, 9/tab break-unless tab? <insert-character-begin> + # todo: decompose insert-at-cursor into editor update and screen update, + # so that 'tab' doesn't render the current line multiple times insert-at-cursor editor, 32/space, screen - insert-at-cursor editor, 32/space, screen + go-render? <- insert-at-cursor editor, 32/space, screen <insert-character-end> - return 1/go-render + return } ] @@ -1653,27 +1681,23 @@ 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?:bool <- minimal-render-for-ctrl-u editor, screen + go-render?:bool <- minimal-render-for-ctrl-u screen, editor return } ] -def minimal-render-for-ctrl-u editor:&:editor, screen:&:screen -> go-render?:bool, screen:&:screen [ +def minimal-render-for-ctrl-u screen:&:screen, editor:&:editor -> go-render?:bool, screen:&:screen [ local-scope load-ingredients - curr-row:num <- get *editor, cursor-row:offset curr-column:num <- get *editor, cursor-column:offset - left:num <- get *editor, left:offset - right:num <- get *editor, right:offset - end:num <- subtract left, right # accumulate the current line as text and render it buf:&:buffer:char <- new-buffer 30 # accumulator for the text we need to render curr:&:duplex-list:char <- get *editor, before-cursor:offset - i:num <- copy 0 + i:num <- copy curr-column + right:num <- get *editor, right:offset { - i <- add i, 1 # if we have a wrapped line, give up and render the whole screen - wrap?:bool <- equal i, end + wrap?:bool <- greater-or-equal i, right return-if wrap?, 1/go-render curr <- next curr break-unless curr @@ -1681,9 +1705,11 @@ def minimal-render-for-ctrl-u editor:&:editor, screen:&:screen -> go-render?:boo b:bool <- equal c, 10 break-if b buf <- append buf, c + i <- add i, 1 loop } curr-line:text <- buffer-to-array buf + curr-row:num <- get *editor, cursor-row:offset render-code screen, curr-line, curr-column, right, curr-row return 0/dont-render ] @@ -1898,12 +1924,12 @@ after <handle-special-character> [ deleted-cells:&:duplex-list:char <- delete-to-end-of-line editor <delete-to-end-of-line-end> # checks if we can do a minimal render and if we can it will do a minimal render - go-render?:bool <- minimal-render-for-ctrl-k editor, screen, deleted-cells + go-render?:bool <- minimal-render-for-ctrl-k screen, editor, deleted-cells return } ] -def minimal-render-for-ctrl-k editor:&:editor, screen:&:screen, deleted-cells:&:duplex-list:char -> go-render?:bool, screen:&:screen [ +def minimal-render-for-ctrl-k screen:&:screen, editor:&:editor, deleted-cells:&:duplex-list:char -> go-render?:bool, screen:&:screen [ local-scope load-ingredients # if we deleted nothing, there's nothing to render @@ -1920,9 +1946,7 @@ def minimal-render-for-ctrl-k editor:&:editor, screen:&:screen, deleted-cells:&: # accumulate the current line as text and render it buf:&:buffer:char <- new-buffer 30 # accumulator for the text we need to render curr:&:duplex-list:char <- get *editor, before-cursor:offset - i:num <- copy 0 { - i <- add i, 1 # check if we are at the end of the line curr <- next curr break-unless curr |