From 17f4b41251658335d706bfb37fed25a7cf78534a Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 29 Jun 2015 12:01:32 -0700 Subject: 1677 --- edit.mu | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'edit.mu') diff --git a/edit.mu b/edit.mu index c561956d..47696fe4 100644 --- a/edit.mu +++ b/edit.mu @@ -444,7 +444,7 @@ recipe event-loop [ ] recipe handle-event [ - default-space:address:array:location <- new location:type, 30:literal + default-space:address:array:location <- new location:type, 40:literal screen:address <- next-ingredient console:address <- next-ingredient editor:address:editor-data <- next-ingredient @@ -506,6 +506,27 @@ recipe handle-event [ break-unless at-newline?:boolean cursor-row:address:number/deref <- add cursor-row:address:number/deref, 1:literal cursor-column:address:number/deref <- copy 0:literal + # todo: what happens when cursor is too far down? + screen-height:number <- screen-height screen:address + above-screen-bottom?:boolean <- lesser-than cursor-row:address:number/deref, screen-height:number + assert above-screen-bottom?:boolean, [unimplemented: moving past bottom of screen] + reply + } + # if the line wraps, move cursor to start of next row + { + # if we're at the column just before the wrap indicator + right:number <- get editor:address:editor-data/deref, right:offset + wrap-column:number <- subtract right:number, 1:literal + at-wrap?:boolean <- equal cursor-column:address:number/deref, wrap-column:number + break-unless at-wrap?:boolean + # and if character after next isn't newline + # TODO + cursor-row:address:number/deref <- add cursor-row:address:number/deref, 1:literal + cursor-column:address:number/deref <- copy 0:literal + # todo: what happens when cursor is too far down? + screen-height:number <- screen-height screen:address + above-screen-bottom?:boolean <- lesser-than cursor-row:address:number/deref, screen-height:number + assert above-screen-bottom?:boolean, [unimplemented: moving past bottom of screen] reply } # otherwise move cursor one character right @@ -994,6 +1015,30 @@ d] ] ] +scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow [ + assume-screen 10:literal/width, 5:literal/height + 1:address:array:character <- new [abcdef] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right + assume-console [ + left-click 0, 3 + press 65514 # right arrow + ] + run [ + event-loop screen:address, console:address, 2:address:editor-data + 3:number <- get 2:address:editor-data/deref, cursor-row:offset + 4:number <- get 2:address:editor-data/deref, cursor-column:offset + ] + screen-should-contain [ + .abcd↩ . + .ef . + . . + ] + memory-should-contain [ + 3 <- 1 + 4 <- 0 + ] +] + scenario editor-moves-cursor-to-next-line-with-right-arrow-at-end-of-line [ assume-screen 10:literal/width, 5:literal/height 1:address:array:character <- new [abc -- cgit 1.4.1-2-gfad0