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 [
280'>280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442