From 92eccaea5ac39f4c362d216b8a74edf6aac3af4a Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 12 Dec 2022 23:17:02 -0800 Subject: bugfix in changing shape mid-stroke --- drawing_tests.lua | 2 +- edit.lua | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drawing_tests.lua b/drawing_tests.lua index 80a91f1..8bcaa43 100644 --- a/drawing_tests.lua +++ b/drawing_tests.lua @@ -185,7 +185,7 @@ function test_draw_circle_mid_stroke() -- draw a circle App.mouse_move(Editor_state.left+4, Editor_state.top+Drawing_padding_top+4) -- hover on drawing edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1) - edit.run_after_keychord(Editor_state, 'o') + edit.run_after_textinput(Editor_state, 'o') edit.run_after_mouse_release(Editor_state, Editor_state.left+35+30, Editor_state.top+Drawing_padding_top+36, 1) local drawing = Editor_state.lines[1] check_eq(#drawing.shapes, 1, 'F - test_draw_circle_mid_stroke/#shapes') diff --git a/edit.lua b/edit.lua index a7d3027..0a30c77 100644 --- a/edit.lua +++ b/edit.lua @@ -289,8 +289,11 @@ function edit.textinput(State, t) p.name = p.name..t record_undo_event(State, {before=before, after=snapshot(State, State.lines.current_drawing_index)}) else - for _,line_cache in ipairs(State.line_cache) do line_cache.starty = nil end -- just in case we scroll - Text.textinput(State, t) + local drawing_index, drawing = Drawing.current_drawing(State) + if drawing_index == nil then + for _,line_cache in ipairs(State.line_cache) do line_cache.starty = nil end -- just in case we scroll + Text.textinput(State, t) + end end schedule_save(State) end -- cgit 1.4.1-2-gfad0 From 39ffe7f411d75687b57232ae39e5b280dccfacc4 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 12 Dec 2022 23:18:42 -0800 Subject: switch a bunch of tests to textinput events textinput is strictly more realistic than keychord_pressed, which doesn't cause any textinput events. Use it wherever possible. --- drawing_tests.lua | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/drawing_tests.lua b/drawing_tests.lua index 8bcaa43..36ad2e8 100644 --- a/drawing_tests.lua +++ b/drawing_tests.lua @@ -162,7 +162,7 @@ function test_keys_do_not_affect_shape_when_mouse_up() edit.draw(Editor_state) -- hover over drawing and press 'o' without holding mouse App.mouse_move(Editor_state.left+4, Editor_state.top+Drawing_padding_top+4) -- hover on drawing - edit.run_after_keychord(Editor_state, 'o') + edit.run_after_textinput(Editor_state, 'o') -- no change to drawing mode check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_keys_do_not_affect_shape_when_mouse_up/drawing_mode') -- no change to text either because we didn't run the textinput event @@ -214,7 +214,7 @@ function test_draw_arc() -- draw an arc edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1) App.mouse_move(Editor_state.left+35+30, Editor_state.top+Drawing_padding_top+36) - edit.run_after_keychord(Editor_state, 'a') -- arc mode + edit.run_after_textinput(Editor_state, 'a') -- arc mode edit.run_after_mouse_release(Editor_state, Editor_state.left+35+50, Editor_state.top+Drawing_padding_top+36+50, 1) -- 45° local drawing = Editor_state.lines[1] check_eq(#drawing.shapes, 1, 'F - test_draw_arc/#shapes') @@ -245,10 +245,10 @@ function test_draw_polygon() check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_polygon/baseline/#shapes') -- first point edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1) - edit.run_after_keychord(Editor_state, 'g') -- polygon mode + edit.run_after_textinput(Editor_state, 'g') -- polygon mode -- second point App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+36) - edit.run_after_keychord(Editor_state, 'p') -- add point + edit.run_after_textinput(Editor_state, 'p') -- add point -- final point edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+26, 1) local drawing = Editor_state.lines[1] @@ -284,13 +284,13 @@ function test_draw_rectangle() check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_rectangle/baseline/#shapes') -- first point edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1) - edit.run_after_keychord(Editor_state, 'r') -- rectangle mode + edit.run_after_textinput(Editor_state, 'r') -- rectangle mode -- second point/first edge App.mouse_move(Editor_state.left+42, Editor_state.top+Drawing_padding_top+45) - edit.run_after_keychord(Editor_state, 'p') + edit.run_after_textinput(Editor_state, 'p') -- override second point/first edge App.mouse_move(Editor_state.left+75, Editor_state.top+Drawing_padding_top+76) - edit.run_after_keychord(Editor_state, 'p') + edit.run_after_textinput(Editor_state, 'p') -- release (decides 'thickness' of rectangle perpendicular to first edge) edit.run_after_mouse_release(Editor_state, Editor_state.left+15, Editor_state.top+Drawing_padding_top+26, 1) local drawing = Editor_state.lines[1] @@ -329,13 +329,13 @@ function test_draw_rectangle_intermediate() check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_rectangle_intermediate/baseline/#shapes') -- first point edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1) - edit.run_after_keychord(Editor_state, 'r') -- rectangle mode + edit.run_after_textinput(Editor_state, 'r') -- rectangle mode -- second point/first edge App.mouse_move(Editor_state.left+42, Editor_state.top+Drawing_padding_top+45) - edit.run_after_keychord(Editor_state, 'p') + edit.run_after_textinput(Editor_state, 'p') -- override second point/first edge App.mouse_move(Editor_state.left+75, Editor_state.top+Drawing_padding_top+76) - edit.run_after_keychord(Editor_state, 'p') + edit.run_after_textinput(Editor_state, 'p') local drawing = Editor_state.lines[1] check_eq(#drawing.points, 3, 'F - test_draw_rectangle_intermediate/#points') -- currently includes every point added local pending = drawing.pending @@ -366,13 +366,13 @@ function test_draw_square() check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_square/baseline/#shapes') -- first point edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1) - edit.run_after_keychord(Editor_state, 's') -- square mode + edit.run_after_textinput(Editor_state, 's') -- square mode -- second point/first edge App.mouse_move(Editor_state.left+42, Editor_state.top+Drawing_padding_top+45) - edit.run_after_keychord(Editor_state, 'p') + edit.run_after_textinput(Editor_state, 'p') -- override second point/first edge App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+66) - edit.run_after_keychord(Editor_state, 'p') + edit.run_after_textinput(Editor_state, 'p') -- release (decides which side of first edge to draw square on) edit.run_after_mouse_release(Editor_state, Editor_state.left+15, Editor_state.top+Drawing_padding_top+26, 1) local drawing = Editor_state.lines[1] @@ -594,13 +594,13 @@ function test_delete_point_from_polygon() edit.draw(Editor_state) -- first point edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1) - edit.run_after_keychord(Editor_state, 'g') -- polygon mode + edit.run_after_textinput(Editor_state, 'g') -- polygon mode -- second point App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+36) - edit.run_after_keychord(Editor_state, 'p') -- add point + edit.run_after_textinput(Editor_state, 'p') -- add point -- third point App.mouse_move(Editor_state.left+35, Editor_state.top+Drawing_padding_top+26) - edit.run_after_keychord(Editor_state, 'p') -- add point + edit.run_after_textinput(Editor_state, 'p') -- add point -- fourth point edit.run_after_mouse_release(Editor_state, Editor_state.left+14, Editor_state.top+Drawing_padding_top+16, 1) local drawing = Editor_state.lines[1] @@ -626,10 +626,10 @@ function test_delete_point_from_polygon() edit.draw(Editor_state) -- first point edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1) - edit.run_after_keychord(Editor_state, 'g') -- polygon mode + edit.run_after_textinput(Editor_state, 'g') -- polygon mode -- second point App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+36) - edit.run_after_keychord(Editor_state, 'p') -- add point + edit.run_after_textinput(Editor_state, 'p') -- add point -- third point edit.run_after_mouse_release(Editor_state, Editor_state.left+14, Editor_state.top+Drawing_padding_top+16, 1) local drawing = Editor_state.lines[1] -- cgit 1.4.1-2-gfad0 From d63178244bfff87f0b6e17f0a67305fe684193ae Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 12 Dec 2022 23:31:50 -0800 Subject: switch one call back to keychord_pressed I don't understand why, but we need to fix production. --- drawing_tests.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drawing_tests.lua b/drawing_tests.lua index 36ad2e8..feadd85 100644 --- a/drawing_tests.lua +++ b/drawing_tests.lua @@ -162,7 +162,7 @@ function test_keys_do_not_affect_shape_when_mouse_up() edit.draw(Editor_state) -- hover over drawing and press 'o' without holding mouse App.mouse_move(Editor_state.left+4, Editor_state.top+Drawing_padding_top+4) -- hover on drawing - edit.run_after_textinput(Editor_state, 'o') + edit.run_after_keychord(Editor_state, 'o') -- no change to drawing mode check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_keys_do_not_affect_shape_when_mouse_up/drawing_mode') -- no change to text either because we didn't run the textinput event -- cgit 1.4.1-2-gfad0