From 3dae8ffc3b3a8a10a2ba645e3f4830a87fa5ab1e Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 23 Dec 2021 12:58:31 -0800 Subject: toot-toot: cursor_down now handles wrapping lines --- toot-toot.tlv | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'toot-toot.tlv') 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: -- cgit 1.4.1-2-gfad0