about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--text.lua3
-rw-r--r--text_tests.lua10
2 files changed, 13 insertions, 0 deletions
diff --git a/text.lua b/text.lua
index 7fa4d2e..88ee18d 100644
--- a/text.lua
+++ b/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
diff --git a/text_tests.lua b/text_tests.lua
index c11ef6e..ae7e794 100644
--- a/text_tests.lua
+++ b/text_tests.lua
@@ -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}