diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2017-06-19 11:19:21 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2017-06-19 11:19:21 -0700 |
commit | b755631561fd1a9223effcc833e2c8201582f63d (patch) | |
tree | fca63fac6b40d9efe43620ef04764e5d6fe6b47a /edit | |
parent | 458dbc54a25ba823b0ef7db274602bd66c93ab69 (diff) | |
download | mu-b755631561fd1a9223effcc833e2c8201582f63d.tar.gz |
3926
Bugfix: when you hit `enter`, the cursor-row does not increment in *one* special situation: when the line wraps and the cursor is right at the start of one of the wrapped lines.
Diffstat (limited to 'edit')
-rw-r--r-- | edit/002-typing.mu | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/edit/002-typing.mu b/edit/002-typing.mu index c6c8edd5..041a6421 100644 --- a/edit/002-typing.mu +++ b/edit/002-typing.mu @@ -874,12 +874,16 @@ def insert-new-line-and-indent editor:&:editor, screen:&:screen -> editor:&:edit left:num <- get *editor, left:offset right:num <- get *editor, right:offset screen-height:num <- screen-height screen + at-start-of-wrapped-line?:bool <- at-start-of-wrapped-line? editor # insert newline insert 10/newline, before-cursor before-cursor <- next before-cursor *editor <- put *editor, before-cursor:offset, before-cursor - cursor-row <- add cursor-row, 1 - *editor <- put *editor, cursor-row:offset, cursor-row + { + break-if at-start-of-wrapped-line? + cursor-row <- add cursor-row, 1 + *editor <- put *editor, cursor-row:offset, cursor-row + } cursor-column <- copy left *editor <- put *editor, cursor-column:offset, cursor-column # maybe scroll @@ -906,6 +910,24 @@ def insert-new-line-and-indent editor:&:editor, screen:&:screen -> editor:&:edit } ] +def at-start-of-wrapped-line? editor:&:editor -> result:bool [ + local-scope + load-ingredients + left:num <- get *editor, left:offset + cursor-column:num <- get *editor, cursor-column:offset + cursor-at-left?:bool <- equal cursor-column, left + return-unless cursor-at-left?, 0/false + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + before-before-cursor:&:duplex-list:char <- prev before-cursor + return-unless before-before-cursor, 0/false # cursor is at start of editor + char-before-cursor:char <- get *before-cursor, value:offset + cursor-after-newline?:bool <- equal char-before-cursor, 10/newline + return-if cursor-after-newline?, 0/false + # if cursor is at left margin and not at start, but previous character is not a newline, + # then we're at start of a wrapped line + return 1/true +] + # takes a pointer 'curr' into the doubly-linked list and its sentinel, counts # the number of spaces at the start of the line containing 'curr'. def line-indent curr:&:duplex-list:char, start:&:duplex-list:char -> result:num [ @@ -986,6 +1008,39 @@ scenario editor-clears-previous-line-completely-after-inserting-newline [ ] ] +scenario editor-splits-wrapped-line-after-inserting-newline [ + local-scope + assume-screen 10/width, 5/height + e:&:editor <- new-editor [abcdef], 0/left, 5/right + editor-render screen, e + screen-should-contain [ + . . + .abcd↩ . + .ef . + .┈┈┈┈┈ . + . . + ] + assume-console [ + left-click 2, 0 + press enter + ] + run [ + editor-event-loop screen, console, e + 10:num/raw <- get *e, cursor-row:offset + 11:num/raw <- get *e, cursor-column:offset + ] + screen-should-contain [ + . . + .abcd . + .ef . + .┈┈┈┈┈ . + ] + memory-should-contain [ + 10 <- 2 # cursor-row + 11 <- 0 # cursor-column + ] +] + scenario editor-inserts-indent-after-newline [ local-scope assume-screen 10/width, 10/height |