about summary refs log tree commit diff stats
path: root/toot-toot.tlv
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-12-23 12:58:31 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-12-23 12:58:31 -0800
commit3dae8ffc3b3a8a10a2ba645e3f4830a87fa5ab1e (patch)
tree3e7e249a0deb7877ccb006b4e10d55413be28cfa /toot-toot.tlv
parent996519c2048fc3feacda0a380712bb91ba691c33 (diff)
downloadteliva-3dae8ffc3b3a8a10a2ba645e3f4830a87fa5ab1e.tar.gz
toot-toot: cursor_down now handles wrapping lines
Diffstat (limited to 'toot-toot.tlv')
-rw-r--r--toot-toot.tlv39
1 files changed, 31 insertions, 8 deletions
diff --git a/toot-toot.tlv b/toot-toot.tlv
index 1b98827..2b320b9 100644
--- a/toot-toot.tlv
+++ b/toot-toot.tlv
@@ -347,11 +347,18 @@
     >  while true do
     >    if i > max then
     >      -- current line is at bottom
+    >      if col >= width then
+    >        return i
+    >      end
     >      return old_idx
     >    end
     >    if s[i] == '\n' then
     >      break
     >    end
+    >    if i - old_idx >= width then
+    >      return i
+    >    end
+    >    col = col+1
     >    i = i+1
     >  end
     >  -- compute index at same column on next line
@@ -376,14 +383,30 @@
     >end
     >
     >function test_cursor_down()
-    >  check_eq(cursor_down('abc\ndef', 1), 5, 'cursor_down: non-bottom line first char')
-    >  check_eq(cursor_down('abc\ndef', 2), 6, 'cursor_down: non-bottom line mid char')
-    >  check_eq(cursor_down('abc\ndef', 3), 7, 'cursor_down: non-bottom line final char')
-    >  check_eq(cursor_down('abc\ndef', 4), 8, 'cursor_down: non-bottom line end')
-    >  check_eq(cursor_down('abc\ndef', 5), 5, 'cursor_down: bottom line first char')
-    >  check_eq(cursor_down('abc\ndef', 6), 6, 'cursor_down: bottom line mid char')
-    >  check_eq(cursor_down('abc\ndef', 7), 7, 'cursor_down: bottom line final char')
-    >  check_eq(cursor_down('abc\n\ndef', 2), 5, 'cursor_down: to shorter line')
+    >  -- lines that don't wrap
+    >  check_eq(cursor_down('abc\ndef', 1, 5), 5, 'cursor_down: non-bottom line first char')
+    >  check_eq(cursor_down('abc\ndef', 2, 5), 6, 'cursor_down: non-bottom line mid char')
+    >  check_eq(cursor_down('abc\ndef', 3, 5), 7, 'cursor_down: non-bottom line final char')
+    >  check_eq(cursor_down('abc\ndef', 4, 5), 8, 'cursor_down: non-bottom line end')
+    >  check_eq(cursor_down('abc\ndef', 5, 5), 5, 'cursor_down: bottom line first char')
+    >  check_eq(cursor_down('abc\ndef', 6, 5), 6, 'cursor_down: bottom line mid char')
+    >  check_eq(cursor_down('abc\ndef', 7, 5), 7, 'cursor_down: bottom line final char')
+    >  check_eq(cursor_down('abc\n\ndef', 2, 5), 5, 'cursor_down: to shorter line')
+    >
+    >  -- within a single wrapping line
+    >  --   |abcde|  <-- wrap, no newline
+    >  --   |fgh  |
+    >  check_eq(cursor_down('abcdefgh', 1, 5), 6, 'cursor_down from wrapping line: first char')
+    >  check_eq(cursor_down('abcdefgh', 2, 5), 7, 'cursor_down from wrapping line: mid char')
+    >  check_eq(cursor_down('abcdefgh', 5, 5), 9, 'cursor_down from wrapping line: to shorter line')
+    >
+    >  -- within a single very long wrapping line
+    >  --   |abcde|  <-- wrap, no newline
+    >  --   |fghij|  <-- wrap, no newline
+    >  --   |klm  |
+    >  check_eq(cursor_down('abcdefghijklm', 1, 5), 6, 'cursor_down within wrapping line: first char')
+    >  check_eq(cursor_down('abcdefghijklm', 2, 5), 7, 'cursor_down within wrapping line: mid char')
+    >  check_eq(cursor_down('abcdefghijklm', 5, 5), 10, 'cursor_down within wrapping line: final char')
     >end
 - __teliva_timestamp: original
   cursor_up: