about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--edit/002-typing.mu2
-rw-r--r--edit/003-shortcuts.mu92
-rw-r--r--sandbox/003-shortcuts.mu90
3 files changed, 176 insertions, 8 deletions
diff --git a/edit/002-typing.mu b/edit/002-typing.mu
index c6c8edd5..fca869e7 100644
--- a/edit/002-typing.mu
+++ b/edit/002-typing.mu
@@ -7,7 +7,7 @@ def! main text:text [
   load-ingredients
   open-console
   clear-screen 0/screen  # non-scrolling app
-  editor:&:editor <- new-editor text, 5/left, 45/right
+  editor:&:editor <- new-editor text, 5/left, 10/right
   editor-render 0/screen, editor
   editor-event-loop 0/screen, 0/console, editor
   close-console
diff --git a/edit/003-shortcuts.mu b/edit/003-shortcuts.mu
index d24be357..f783c06d 100644
--- a/edit/003-shortcuts.mu
+++ b/edit/003-shortcuts.mu
@@ -1012,15 +1012,13 @@ def move-to-previous-line editor:&:editor -> go-render?:bool, editor:&:editor [
   {
     # if cursor not at top, move it
     break-if already-at-top?
-    # if not at newline, move to start of line (previous newline)
+    # if not at start of screen line, move to start of screen line (previous newline)
     # then scan back another line
     # if either step fails, give up without modifying cursor or coordinates
     curr:&:duplex-list:char <- copy before-cursor
     old:&:duplex-list:char <- copy curr
     {
-      c2:char <- get *curr, value:offset
-      at-newline?:bool <- equal c2, 10/newline
-      break-if at-newline?
+      break-unless cursor-column
       curr <- before-previous-screen-line curr, editor
       no-motion?:bool <- equal curr, old
       return-if no-motion?
@@ -1177,6 +1175,92 @@ ghi]
   ]
 ]
 
+scenario editor-moves-to-top-line-in-presence-of-wrapped-line [
+  local-scope
+  assume-screen 10/width, 5/height
+  s:text <- new [abcde]
+  e:&:editor <- new-editor s, 0/left, 5/right
+  editor-render screen, e
+  screen-should-contain [
+    .          .
+    .abcd↩     .
+    .e         .
+    .┈┈┈┈┈     .
+  ]
+  $clear-trace
+  assume-console [
+    left-click 2, 0
+    press up-arrow
+  ]
+  run [
+    editor-event-loop screen, console, e
+    3:num/raw <- get *e, cursor-row:offset
+    4:num/raw <- get *e, cursor-column:offset
+  ]
+  memory-should-contain [
+    3 <- 1
+    4 <- 0
+  ]
+  check-trace-count-for-label 0, [print-character]
+  assume-console [
+    type [0]
+  ]
+  run [
+    editor-event-loop screen, console, e
+  ]
+  screen-should-contain [
+    .          .
+    .0abc↩     .
+    .de        .
+    .┈┈┈┈┈     .
+  ]
+]
+
+scenario editor-moves-to-top-line-in-presence-of-wrapped-line-2 [
+  local-scope
+  assume-screen 10/width, 5/height
+  s:text <- new [abc
+defgh]
+  e:&:editor <- new-editor s, 0/left, 5/right
+  editor-render screen, e
+  screen-should-contain [
+    .          .
+    .abc       .
+    .defg↩     .
+    .h         .
+    .┈┈┈┈┈     .
+  ]
+  $clear-trace
+  assume-console [
+    left-click 3, 0
+    press up-arrow
+    press up-arrow
+  ]
+  run [
+    editor-event-loop screen, console, e
+    3:num/raw <- get *e, cursor-row:offset
+    4:num/raw <- get *e, cursor-column:offset
+  ]
+  memory-should-contain [
+    3 <- 1
+    4 <- 0
+  ]
+  check-trace-count-for-label 0, [print-character]
+  assume-console [
+    type [0]
+  ]
+  run [
+    editor-event-loop screen, console, e
+  ]
+  screen-should-contain [
+    .          .
+    .0abc      .
+    .defg↩     .
+    .h         .
+    .┈┈┈┈┈     .
+  ]
+]
+
 # down arrow
 
 scenario editor-moves-to-next-line-with-down-arrow [
diff --git a/sandbox/003-shortcuts.mu b/sandbox/003-shortcuts.mu
index 41102275..e9d1a349 100644
--- a/sandbox/003-shortcuts.mu
+++ b/sandbox/003-shortcuts.mu
@@ -1012,9 +1012,7 @@ def move-to-previous-line editor:&:editor -> editor:&:editor [
     curr:&:duplex-list:char <- copy before-cursor
     old:&:duplex-list:char <- copy curr
     {
-      c2:char <- get *curr, value:offset
-      at-newline?:bool <- equal c2, 10/newline
-      break-if at-newline?
+      break-unless cursor-column
       curr <- before-previous-screen-line curr, editor
       no-motion?:bool <- equal curr, old
       return-if no-motion?
@@ -1164,6 +1162,92 @@ ghi]
   ]
 ]
 
+scenario editor-moves-to-top-line-in-presence-of-wrapped-line [
+  local-scope
+  assume-screen 10/width, 5/height
+  s:text <- new [abcde]
+  e:&:editor <- new-editor s, 0/left, 5/right
+  editor-render screen, e
+  screen-should-contain [
+    .          .
+    .abcd↩     .
+    .e         .
+    .┈┈┈┈┈     .
+  ]
+  $clear-trace
+  assume-console [
+    left-click 2, 0
+    press up-arrow
+  ]
+  run [
+    editor-event-loop screen, console, e
+    3:num/raw <- get *e, cursor-row:offset
+    4:num/raw <- get *e, cursor-column:offset
+  ]
+  memory-should-contain [
+    3 <- 1
+    4 <- 0
+  ]
+  check-trace-count-for-label 0, [print-character]
+  assume-console [
+    type [0]
+  ]
+  run [
+    editor-event-loop screen, console, e
+  ]
+  screen-should-contain [
+    .          .
+    .0abc↩     .
+    .de        .
+    .┈┈┈┈┈     .
+  ]
+]
+
+scenario editor-moves-to-top-line-in-presence-of-wrapped-line-2 [
+  local-scope
+  assume-screen 10/width, 5/height
+  s:text <- new [abc
+defgh]
+  e:&:editor <- new-editor s, 0/left, 5/right
+  editor-render screen, e
+  screen-should-contain [
+    .          .
+    .abc       .
+    .defg↩     .
+    .h         .
+    .┈┈┈┈┈     .
+  ]
+  $clear-trace
+  assume-console [
+    left-click 3, 0
+    press up-arrow
+    press up-arrow
+  ]
+  run [
+    editor-event-loop screen, console, e
+    3:num/raw <- get *e, cursor-row:offset
+    4:num/raw <- get *e, cursor-column:offset
+  ]
+  memory-should-contain [
+    3 <- 1
+    4 <- 0
+  ]
+  check-trace-count-for-label 0, [print-character]
+  assume-console [
+    type [0]
+  ]
+  run [
+    editor-event-loop screen, console, e
+  ]
+  screen-should-contain [
+    .          .
+    .0abc      .
+    .defg↩     .
+    .h         .
+    .┈┈┈┈┈     .
+  ]
+]
+
 # down arrow
 
 scenario editor-moves-to-next-line-with-down-arrow [
67'>467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574