about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--edit/003-shortcuts.mu133
1 files changed, 131 insertions, 2 deletions
diff --git a/edit/003-shortcuts.mu b/edit/003-shortcuts.mu
index 941d316d..4d136013 100644
--- a/edit/003-shortcuts.mu
+++ b/edit/003-shortcuts.mu
@@ -1627,6 +1627,8 @@ scenario editor-deletes-to-start-of-line-with-ctrl-u [
   s:text <- new [123
 456]
   e:&:editor <- new-editor s, 0/left, 10/right
+  editor-render screen, e
+  $clear-trace
   # start on second line, press ctrl-u
   assume-console [
     left-click 2, 2
@@ -1643,6 +1645,7 @@ scenario editor-deletes-to-start-of-line-with-ctrl-u [
     .┈┈┈┈┈┈┈┈┈┈.
     .          .
   ]
+  check-trace-count-for-label 10, [print-character]
 ]
 
 after <handle-special-character> [
@@ -1652,8 +1655,40 @@ after <handle-special-character> [
     <delete-to-start-of-line-begin>
     deleted-cells:&:duplex-list:char <- delete-to-start-of-line editor
     <delete-to-start-of-line-end>
-    return 1/go-render
+    go-render?:bool <- minimal-render-for-ctrl-u editor, screen
+    return
+  }
+]
+
+def minimal-render-for-ctrl-u editor:&:editor screen:&:screen -> go-render?:bool screen:&:screen [
+  local-scope
+  load-ingredients
+  # variables
+  curr-row:num <- get *editor cursor-row:offset
+  curr-column:num <- get *editor cursor-column:offset
+  left:num <- get *editor left:offset
+  right:num <- get *editor right:offset
+  end:num <- subtract left right
+  # accumulate the current line as text and render it
+  buff:&:buffer:char <- new-buffer 30  # accumulator for the text we need to render
+  curr:&:duplex-list:char <- get *editor before-cursor:offset
+  i:num <- copy 0
+  {
+    i <- add i 1
+    wrap?:bool <- equal i end
+    return-if wrap?, 1/do-render
+    curr <- next curr
+    break-unless curr
+    c:char <- get *curr value:offset
+    b:bool <- equal c 10
+    break-if b
+    buff <- append buff c
+    loop
   }
+  # if everything passes render minimally
+  text:text <- buffer-to-array buff
+  render-code screen text curr-column right curr-row
+  return 0/dont-render
 ]
 
 def delete-to-start-of-line editor:&:editor -> result:&:duplex-list:char, editor:&:editor [
@@ -1690,6 +1725,8 @@ scenario editor-deletes-to-start-of-line-with-ctrl-u-2 [
   s:text <- new [123
 456]
   e:&:editor <- new-editor s, 0/left, 10/right
+  editor-render screen, e
+  $clear-trace
   # start on first line (no newline before), press ctrl-u
   assume-console [
     left-click 1, 2
@@ -1706,6 +1743,7 @@ scenario editor-deletes-to-start-of-line-with-ctrl-u-2 [
     .┈┈┈┈┈┈┈┈┈┈.
     .          .
   ]
+  check-trace-count-for-label 10, [print-character]
 ]
 
 scenario editor-deletes-to-start-of-line-with-ctrl-u-3 [
@@ -1714,6 +1752,8 @@ scenario editor-deletes-to-start-of-line-with-ctrl-u-3 [
   s:text <- new [123
 456]
   e:&:editor <- new-editor s, 0/left, 10/right
+  editor-render screen, e
+  $clear-trace
   # start past end of line, press ctrl-u
   assume-console [
     left-click 1, 3
@@ -1730,6 +1770,7 @@ scenario editor-deletes-to-start-of-line-with-ctrl-u-3 [
     .┈┈┈┈┈┈┈┈┈┈.
     .          .
   ]
+  check-trace-count-for-label 10, [print-character]
 ]
 
 scenario editor-deletes-to-start-of-final-line-with-ctrl-u [
@@ -1738,6 +1779,8 @@ scenario editor-deletes-to-start-of-final-line-with-ctrl-u [
   s:text <- new [123
 456]
   e:&:editor <- new-editor s, 0/left, 10/right
+  editor-render screen, e
+  $clear-trace
   # start past end of final line, press ctrl-u
   assume-console [
     left-click 2, 3
@@ -1754,6 +1797,7 @@ scenario editor-deletes-to-start-of-final-line-with-ctrl-u [
     .┈┈┈┈┈┈┈┈┈┈.
     .          .
   ]
+  check-trace-count-for-label 10, [print-character]
 ]
 
 # ctrl-k - delete text from cursor to end of line (but not the newline)
@@ -1764,6 +1808,8 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k [
   s:text <- new [123
 456]
   e:&:editor <- new-editor s, 0/left, 10/right
+  editor-render screen, e
+  $clear-trace
   # start on first line, press ctrl-k
   assume-console [
     left-click 1, 1
@@ -1780,6 +1826,7 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k [
     .┈┈┈┈┈┈┈┈┈┈.
     .          .
   ]
+  check-trace-count-for-label 9, [print-character]
 ]
 
 after <handle-special-character> [
@@ -1789,8 +1836,46 @@ after <handle-special-character> [
     <delete-to-end-of-line-begin>
     deleted-cells:&:duplex-list:char <- delete-to-end-of-line editor
     <delete-to-end-of-line-end>
-    return 1/go-render
+    # checks if we can do a minimal render and if we can it will do a minimal render
+    go-render?:bool <- minimal-render-for-ctrl-k editor, screen, deleted-cells
+    return
+  }
+]
+
+def minimal-render-for-ctrl-k editor:&:editor screen:&:screen deleted-cells:&:duplex-list:char -> go-render?:bool screen:&:screen [
+  local-scope
+  load-ingredients
+  # if we deleted nothing, there's nothing to render
+  return-unless deleted-cells, 0/dont-render
+  # if we have a wrapped line, give up and render the whole screen
+  curr-column:num <- get *editor cursor-column:offset
+  dc-len:num <- length deleted-cells
+  row-len:num <- add curr-column dc-len
+  left:num <- get *editor left:offset
+  right:num <- get *editor right:offset
+  end:num <- subtract right left
+  wrap?:bool <- greater-or-equal row-len end
+  return-if wrap? 1/do-render
+  # accumulate the current line as text and render it
+  buff:&:buffer:char <- new-buffer 30  # accumulator for the text we need to render
+  curr:&:duplex-list:char <- get *editor before-cursor:offset
+  i:num <- copy 0
+  {
+    i <- add i 1
+    # check if we are at the end of the line
+    curr <- next curr
+    break-unless curr
+    c:char <- get *curr value:offset
+    # check if we have a newline
+    b:bool <- equal c 10
+    break-if b
+    buff <- append buff c
+    loop
   }
+  text:text <- buffer-to-array buff
+  curr-row:num <- get *editor cursor-row:offset
+  render-code screen text curr-column right curr-row
+  return 0/dont-render
 ]
 
 def delete-to-end-of-line editor:&:editor -> result:&:duplex-list:char, editor:&:editor [
@@ -1819,6 +1904,8 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-2 [
   s:text <- new [123
 456]
   e:&:editor <- new-editor s, 0/left, 10/right
+  editor-render screen, e
+  $clear-trace
   # start on second line (no newline after), press ctrl-k
   assume-console [
     left-click 2, 1
@@ -1835,6 +1922,7 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-2 [
     .┈┈┈┈┈┈┈┈┈┈.
     .          .
   ]
+  check-trace-count-for-label 9, [print-character]
 ]
 
 scenario editor-deletes-to-end-of-line-with-ctrl-k-3 [
@@ -1843,6 +1931,8 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-3 [
   s:text <- new [123
 456]
   e:&:editor <- new-editor s, 0/left, 10/right
+  editor-render screen, e
+  $clear-trace
   # start at end of line
   assume-console [
     left-click 1, 2
@@ -1859,6 +1949,7 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-3 [
     .┈┈┈┈┈┈┈┈┈┈.
     .          .
   ]
+  check-trace-count-for-label 8, [print-character]
 ]
 
 scenario editor-deletes-to-end-of-line-with-ctrl-k-4 [
@@ -1867,6 +1958,8 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-4 [
   s:text <- new [123
 456]
   e:&:editor <- new-editor s, 0/left, 10/right
+  editor-render screen, e
+  $clear-trace
   # start past end of line
   assume-console [
     left-click 1, 3
@@ -1883,6 +1976,7 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-4 [
     .┈┈┈┈┈┈┈┈┈┈.
     .          .
   ]
+  check-trace-count-for-label 7, [print-character]
 ]
 
 scenario editor-deletes-to-end-of-line-with-ctrl-k-5 [
@@ -1891,6 +1985,8 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-5 [
   s:text <- new [123
 456]
   e:&:editor <- new-editor s, 0/left, 10/right
+  editor-render screen, e
+  $clear-trace
   # start at end of text
   assume-console [
     left-click 2, 2
@@ -1907,6 +2003,7 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-5 [
     .┈┈┈┈┈┈┈┈┈┈.
     .          .
   ]
+  check-trace-count-for-label 8, [print-character]
 ]
 
 scenario editor-deletes-to-end-of-line-with-ctrl-k-6 [
@@ -1915,6 +2012,8 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-6 [
   s:text <- new [123
 456]
   e:&:editor <- new-editor s, 0/left, 10/right
+  editor-render screen, e
+  $clear-trace
   # start past end of text
   assume-console [
     left-click 2, 3
@@ -1931,6 +2030,36 @@ scenario editor-deletes-to-end-of-line-with-ctrl-k-6 [
     .┈┈┈┈┈┈┈┈┈┈.
     .          .
   ]
+  # no prints necessary
+  check-trace-count-for-label 0, [print-character]
+]
+
+scenario editor-deletes-to-end-of-wrapped-line-with-ctrl-k [
+  local-scope
+  assume-screen 10/width, 5/height
+  # create an editor with the first line wrapping to a second screen row
+  s:text <- new [1234
+567]
+  e:&:editor <- new-editor s, 0/left, 4/right
+  editor-render screen, e
+  $clear-trace
+  # delete all of the first wrapped line
+  assume-console [
+    press ctrl-k
+  ]
+  run [
+    editor-event-loop screen, console, e
+  ]
+  # screen shows an empty unwrapped first line
+  screen-should-contain [
+    .          .
+    .          .
+    .567       .
+    .┈┈┈┈      .
+    .          .
+  ]
+  # entire screen is refreshed
+  check-trace-count-for-label 16, [print-character]
 ]
 
 # cursor-down can scroll if necessary