State changes when inserting return are now in sync with other
characters.
This commit is contained in:
Kartik K. Agaram 2022-06-21 07:20:25 -07:00
parent 5a0b6c6a58
commit 9c8285bf08
2 changed files with 8 additions and 1 deletions

View File

@ -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`.

View File

@ -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')