From b755631561fd1a9223effcc833e2c8201582f63d Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 19 Jun 2017 11:19:21 -0700 Subject: 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. --- edit/002-typing.mu | 59 +++++++++++++++++++++++++++++++++++++++++++++++++-- sandbox/002-typing.mu | 59 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 114 insertions(+), 4 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 diff --git a/sandbox/002-typing.mu b/sandbox/002-typing.mu index c6c8edd5..041a6421 100644 --- a/sandbox/002-typing.mu +++ b/sandbox/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 -- cgit 1.4.1-2-gfad0