about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-08-08 22:03:14 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-08-08 22:11:39 -0700
commit37ae39ce3faf5eb3d5e720aed2d2076122fca1ff (patch)
tree97e52b99c93384ec34576d5a493cbaa05d6471ba
parente2548d7007f80f9b1a53f516f6e1c2367f6ab6ff (diff)
downloadmu-37ae39ce3faf5eb3d5e720aed2d2076122fca1ff.tar.gz
1957 - bugfix #2 in scrolling
(#1 was previous commit)

Thanks Caleb Couch.
-rw-r--r--edit.mu64
1 files changed, 57 insertions, 7 deletions
diff --git a/edit.mu b/edit.mu
index 569e8eba..b3818b5b 100644
--- a/edit.mu
+++ b/edit.mu
@@ -2860,6 +2860,7 @@ after +scroll-down [
 
 # takes a pointer into the doubly-linked list, scans ahead at most 'max'
 # positions until the next newline
+# beware: never return null pointer.
 recipe before-start-of-next-line [
   local-scope
   original:address:duplex-list <- next-ingredient
@@ -3160,15 +3161,14 @@ after +scroll-up [
 ]
 
 # takes a pointer into the doubly-linked list, scans back at most 'max'
-# positions to previous newline. Returns original pointer if falls off edge of
-# list.
+# positions to previous newline.
+# beware: never return null pointer.
 recipe start-of-previous-line [
   local-scope
   original:address:duplex-list <- next-ingredient
   max:number <- next-ingredient
   count:number <- copy 0
   curr:address:duplex-list <- copy original
-  reply-unless curr, original
   # if top is at start of line, don't count the previous newline
   {
     c:character <- get *curr, value:offset
@@ -3177,21 +3177,23 @@ recipe start-of-previous-line [
     max <- subtract max, 1
   }
   # skip newline at original
-  curr <- prev-duplex curr
+  prev:address:duplex-list <- prev-duplex curr
+  reply-unless prev, curr
+  curr <- copy prev
   count <- add count, 1
   # now skip before until previous newline
   {
-    reply-unless curr, original
     done?:boolean <- greater-or-equal count, max
     break-if done?
     c:character <- get *curr, value:offset
     at-newline?:boolean <- equal c, 10/newline
     break-if at-newline?
-    curr <- prev-duplex curr
+    prev <- prev-duplex curr
+    break-unless prev
+    curr <- copy prev
     count <- add count, 1
     loop
   }
-  reply-unless curr, original
   reply curr
 ]
 
@@ -3355,6 +3357,54 @@ e]
   ]
 ]
 
+scenario editor-can-scroll-up-to-start-of-file [
+  # screen has 1 line for menu + 3 lines
+  assume-screen 10/width, 4/height
+  # initialize editor with >3 lines
+  1:address:array:character <- new [a
+b
+c
+d]
+  2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right
+  screen-should-contain [
+    .          .
+    .a         .
+    .b         .
+    .c         .
+  ]
+  # position cursor at top of second page, then try to move up to start of
+  # text
+  assume-console [
+    press 65518  # page-down
+    press 65517  # up-arrow
+    press 65517  # up-arrow
+  ]
+  run [
+    editor-event-loop screen:address, console:address, 2:address:editor-data
+  ]
+  # screen slides by one line
+  screen-should-contain [
+    .          .
+    .a         .
+    .b         .
+    .c         .
+  ]
+  # try to move up again
+  assume-console [
+    press 65517  # up-arrow
+  ]
+  run [
+    editor-event-loop screen:address, console:address, 2:address:editor-data
+  ]
+  # screen remains unchanged
+  screen-should-contain [
+    .          .
+    .a         .
+    .b         .
+    .c         .
+  ]
+]
+
 ## putting the environment together out of editors
 
 container programming-environment-data [