about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-06-21 07:20:25 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-06-21 07:24:44 -0700
commit9c8285bf08656bc1b74c6798b326be7145965170 (patch)
tree10652ffcf47499187291647253aa1ae0f347c819
parent5a0b6c6a5804c22a7fe62300ff10b8bf890f083a (diff)
downloadview.love-9c8285bf08656bc1b74c6798b326be7145965170.tar.gz
bugfix
State changes when inserting return are now in sync with other
characters.
-rw-r--r--Manual_tests.md4
-rw-r--r--text.lua5
2 files changed, 8 insertions, 1 deletions
diff --git a/Manual_tests.md b/Manual_tests.md
index 8c1398e..8d4d410 100644
--- a/Manual_tests.md
+++ b/Manual_tests.md
@@ -11,3 +11,7 @@ Lua is dynamically typed. Tests can't patch over lack of type-checking.
   byte offsets with the suffix `_offset`, and character positions as `_pos`.
   For example, `string.sub` should never use a `_pos` to substring, only an
   `_offset`.
+
+* Some ADT/interface support would be helpful in keeping per-line state in
+  sync. Any change to line data should clear line `fragments` and
+  `screen_line_starting_pos`.
diff --git a/text.lua b/text.lua
index 5dbecc9..84f3000 100644
--- a/text.lua
+++ b/text.lua
@@ -355,6 +355,9 @@ function Text.insert_return()
   table.insert(Lines, Cursor1.line+1, {mode='text', data=string.sub(Lines[Cursor1.line].data, byte_offset)})
   Lines[Cursor1.line].data = string.sub(Lines[Cursor1.line].data, 1, byte_offset-1)
   Lines[Cursor1.line].fragments = nil
+  Lines[Cursor1.line].screen_line_starting_pos = nil
+  Lines[Cursor1.line+1].fragments = nil
+  Lines[Cursor1.line+1].screen_line_starting_pos = nil
   Cursor1.line = Cursor1.line+1
   Cursor1.pos = 1
 end
@@ -410,7 +413,7 @@ end
 
 function Text.up()
   assert(Lines[Cursor1.line].mode == 'text')
---?   print('up', Cursor1.pos, Screen_top1.pos)
+--?   print('up', Cursor1.line, Cursor1.pos, Screen_top1.line, Screen_top1.pos)
   local screen_line_index,screen_line_starting_pos = Text.pos_at_start_of_cursor_screen_line()
   if screen_line_starting_pos == 1 then
 --?     print('cursor is at first screen line of its line')