about summary refs log tree commit diff stats
path: root/edit/003-shortcuts.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-06-16 21:16:23 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-06-16 21:48:16 -0700
commit0f64a45c353aadb04cc7e360764e243fa7ea37b1 (patch)
tree8ce6629a19ec36bc61c3bfe0bbec8e4dff3334ad /edit/003-shortcuts.mu
parent1441e507b63f2c48c201c76bc991f7818ab1c987 (diff)
downloadmu-0f64a45c353aadb04cc7e360764e243fa7ea37b1.tar.gz
3918
Bugfix: handle wrapped lines when moving to end of line.
Diffstat (limited to 'edit/003-shortcuts.mu')
-rw-r--r--edit/003-shortcuts.mu50
1 files changed, 47 insertions, 3 deletions
diff --git a/edit/003-shortcuts.mu b/edit/003-shortcuts.mu
index e39e3ce1..d24be357 100644
--- a/edit/003-shortcuts.mu
+++ b/edit/003-shortcuts.mu
@@ -1551,17 +1551,20 @@ def move-to-end-of-line editor:&:editor -> editor:&:editor [
   load-ingredients
   before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset
   cursor-column:num <- get *editor, cursor-column:offset
-  # while not at start of line, move
+  right:num <- get *editor, right:offset
+  # while not at end of line, move
   {
     next:&:duplex-list:char <- next before-cursor
     break-unless next  # end of text
     nextc:char <- get *next, value:offset
     at-end-of-line?:bool <- equal nextc, 10/newline
     break-if at-end-of-line?
-    before-cursor <- copy next
-    *editor <- put *editor, before-cursor:offset, before-cursor
     cursor-column <- add cursor-column, 1
+    at-right?:bool <- equal cursor-column, right
+    break-if at-right?
     *editor <- put *editor, cursor-column:offset, cursor-column
+    before-cursor <- copy next
+    *editor <- put *editor, before-cursor:offset, before-cursor
     loop
   }
 ]
@@ -1644,6 +1647,47 @@ scenario editor-moves-to-end-of-line-with-end-2 [
   check-trace-count-for-label 0, [print-character]
 ]
 
+scenario editor-moves-to-end-of-wrapped-line [
+  local-scope
+  assume-screen 10/width, 5/height
+  s:text <- new [123456
+789]
+  e:&:editor <- new-editor s, 0/left, 5/right
+  editor-render screen, e
+  $clear-trace
+  # start on first line, press 'end'
+  assume-console [
+    left-click 1, 1
+    press end
+  ]
+  run [
+    editor-event-loop screen, console, e
+    10:num/raw <- get *e, cursor-row:offset
+    11:num/raw <- get *e, cursor-column:offset
+  ]
+  # cursor moves to end of line
+  memory-should-contain [
+    10 <- 1
+    11 <- 3
+  ]
+  # no prints
+  check-trace-count-for-label 0, [print-character]
+  # before-cursor is also consistent
+  assume-console [
+    type [a]
+  ]
+  run [
+    editor-event-loop screen, console, e
+  ]
+  screen-should-contain [
+    .          .
+    .123a↩     .
+    .456       .
+    .789       .
+    .┈┈┈┈┈     .
+  ]
+]
+
 # ctrl-u - delete text from start of line until (but not at) cursor
 
 scenario editor-deletes-to-start-of-line-with-ctrl-u [