bugfix in previous commit
I almost pushed this to production. That would have been catastrophic; the very first keystroke anyone typed into the editor would have failed. And in the process, this fixes the next bug on my TODO list! Paste on first line wasn't working. Now it is.
This commit is contained in:
parent
de473046bc
commit
e7a985bd0a
3
text.lua
3
text.lua
|
@ -152,6 +152,7 @@ function Text.insert_at_cursor(t)
|
|||
else
|
||||
byte_offset = 1
|
||||
end
|
||||
--? print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
|
||||
Lines[Cursor1.line].data = string.sub(Lines[Cursor1.line].data, 1, byte_offset-1)..t..string.sub(Lines[Cursor1.line].data, byte_offset)
|
||||
Lines[Cursor1.line].fragments = nil
|
||||
Lines[Cursor1.line].screen_line_starting_pos = nil
|
||||
|
@ -160,6 +161,7 @@ function Text.insert_at_cursor(t)
|
|||
if scroll_down then
|
||||
Text.populate_screen_line_starting_pos(Cursor1.line)
|
||||
Text.snap_cursor_to_bottom_of_screen()
|
||||
--? print('=>', Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -624,6 +626,7 @@ end
|
|||
|
||||
function Text.snap_cursor_to_bottom_of_screen()
|
||||
local top2 = Text.to2(Cursor1)
|
||||
top2.screen_pos = 1 -- start of screen line
|
||||
--? print('cursor pos '..tostring(Cursor1.pos)..' is on the #'..tostring(top2.screen_line)..' screen line down')
|
||||
local y = App.screen.height - Line_height
|
||||
-- duplicate some logic from love.draw
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
-- major tests for text editing flows
|
||||
-- This still isn't quite as thorough as I'd like.
|
||||
|
||||
function test_insert_first_character()
|
||||
io.write('\ntest_insert_first_character')
|
||||
App.screen.init{width=120, height=60}
|
||||
Lines = load_array{}
|
||||
App.draw()
|
||||
App.run_after_textinput('a')
|
||||
local y = Margin_top
|
||||
App.screen.check(y, 'a', 'F - test_insert_first_character/screen:1')
|
||||
end
|
||||
|
||||
function test_draw_text()
|
||||
io.write('\ntest_draw_text')
|
||||
App.screen.init{width=120, height=60}
|
||||
|
|
Loading…
Reference in New Issue