about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-07-13 08:38:07 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-07-13 08:40:04 -0700
commit22ad5373c5e4e4c68b4a9f8fcde83caee92237a2 (patch)
tree7635147ee789b900d9aed70948cd076a52e14716
parent6659de60f365cf31290790a9d84f46c16eb6301b (diff)
downloadtext.love-22ad5373c5e4e4c68b4a9f8fcde83caee92237a2.tar.gz
a bug I've never run into
The previous commit was failing inside a test that I can't reproduce
manually. Perhaps it's something about how often draw/update run in
practice. Anyways, it's definitely uncovered a real issue.
-rw-r--r--drawing.lua3
-rw-r--r--drawing_tests.lua2
-rw-r--r--edit.lua10
3 files changed, 10 insertions, 5 deletions
diff --git a/drawing.lua b/drawing.lua
index 71595a8..587c24c 100644
--- a/drawing.lua
+++ b/drawing.lua
@@ -241,9 +241,6 @@ function Drawing.update(State)
   if State.lines.current_drawing == nil then return end
   local drawing = State.lines.current_drawing
   assert(drawing.mode == 'drawing')
-  if drawing.y == nil then
-    return  -- first draw?
-  end
   local pmx, pmy = App.mouse_x(), App.mouse_y()
   local mx = Drawing.coord(pmx-State.left, State.width)
   local my = Drawing.coord(pmy-drawing.y, State.width)
diff --git a/drawing_tests.lua b/drawing_tests.lua
index 96e4bd8..38a0144 100644
--- a/drawing_tests.lua
+++ b/drawing_tests.lua
@@ -643,6 +643,7 @@ function test_undo_name_point()
   check_eq(p2.y, 36, 'F - test_undo_name_point/baseline/p2:y')
   check_nil(p2.name, 'F - test_undo_name_point/baseline/p2:name')
   check_eq(#Editor_state.history, 1, 'F - test_undo_name_point/baseline/history:1')
+--?   print('a', Editor_state.lines.current_drawing)
   -- enter 'name' mode without moving the mouse
   edit.run_after_keychord(Editor_state, 'C-n')
   edit.run_after_textinput(Editor_state, 'A')
@@ -650,6 +651,7 @@ function test_undo_name_point()
   check_eq(p2.name, 'A', 'F - test_undo_name_point/baseline')
   check_eq(#Editor_state.history, 3, 'F - test_undo_name_point/baseline/history:2')
   check_eq(Editor_state.next_history, 4, 'F - test_undo_name_point/baseline/next_history')
+--?   print('b', Editor_state.lines.current_drawing)
   -- undo
   edit.run_after_keychord(Editor_state, 'C-z')
   local drawing = Editor_state.lines[1]
diff --git a/edit.lua b/edit.lua
index 0958817..1929c52 100644
--- a/edit.lua
+++ b/edit.lua
@@ -352,7 +352,10 @@ function edit.keychord_pressed(State, chord, key)
       State.cursor1 = deepcopy(src.cursor)
       State.selection1 = deepcopy(src.selection)
       patch(State.lines, event.after, event.before)
-      Text.redraw_all(State)  -- if we're scrolling, reclaim all fragments to avoid memory leaks
+      -- invalidate various cached bits of lines
+      State.lines.current_drawing = nil
+      -- if we're scrolling, reclaim all fragments to avoid memory leaks
+      Text.redraw_all(State)
       schedule_save(State)
     end
   elseif chord == 'C-y' then
@@ -364,7 +367,10 @@ function edit.keychord_pressed(State, chord, key)
       State.cursor1 = deepcopy(src.cursor)
       State.selection1 = deepcopy(src.selection)
       patch(State.lines, event.before, event.after)
-      Text.redraw_all(State)  -- if we're scrolling, reclaim all fragments to avoid memory leaks
+      -- invalidate various cached bits of lines
+      State.lines.current_drawing = nil
+      -- if we're scrolling, reclaim all fragments to avoid memory leaks
+      Text.redraw_all(State)
       schedule_save(State)
     end
   -- clipboard