diff options
-rw-r--r-- | drawing.lua | 7 | ||||
-rw-r--r-- | drawing_tests.lua | 22 | ||||
-rw-r--r-- | main.lua | 5 |
3 files changed, 28 insertions, 6 deletions
diff --git a/drawing.lua b/drawing.lua index 04bf1d2..cff5620 100644 --- a/drawing.lua +++ b/drawing.lua @@ -287,7 +287,9 @@ function Drawing.mouse_released(x,y, button) elseif Lines.current_drawing then local drawing = Lines.current_drawing if drawing.pending then - if drawing.pending.mode == 'freehand' then + if drawing.pending.mode == nil then + -- nothing pending + elseif drawing.pending.mode == 'freehand' then -- the last point added during update is good enough table.insert(drawing.shapes, drawing.pending) elseif drawing.pending.mode == 'line' then @@ -540,6 +542,9 @@ function Drawing.keychord_pressed(chord) if drawing then drawing.show_help = true end + elseif chord == 'escape' and App.mouse_down(1) then + local _,drawing = Drawing.current_drawing() + drawing.pending = {} end end diff --git a/drawing_tests.lua b/drawing_tests.lua index 0b34c94..4ec9690 100644 --- a/drawing_tests.lua +++ b/drawing_tests.lua @@ -118,6 +118,28 @@ function test_draw_circle() check_eq(center.y, 36, 'F - test_draw_circle/center:y') end +function test_cancel_stroke() + io.write('\ntest_cancel_stroke') + -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end) + Filename = 'foo' + App.screen.init{width=Margin_width+256, height=300} -- drawing coordinates 1:1 with pixels + Lines = load_array{'```lines', '```', ''} + Current_drawing_mode = 'line' + App.draw() + check_eq(#Lines, 2, 'F - test_cancel_stroke/baseline/#lines') + check_eq(Lines[1].mode, 'drawing', 'F - test_cancel_stroke/baseline/mode') + check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_cancel_stroke/baseline/y') + check_eq(Lines[1].h, 128, 'F - test_cancel_stroke/baseline/y') + check_eq(#Lines[1].shapes, 0, 'F - test_cancel_stroke/baseline/#shapes') + -- start drawing a line + App.run_after_mouse_press(Margin_left+5, Margin_top+Drawing_padding_top+6, 1) + -- cancel + App.run_after_keychord('escape') + App.run_after_mouse_release(Margin_left+35, Margin_top+Drawing_padding_top+36, 1) + local drawing = Lines[1] + check_eq(#drawing.shapes, 0, 'F - test_cancel_stroke/#shapes') +end + function test_keys_do_not_affect_shape_when_mouse_up() io.write('\ntest_keys_do_not_affect_shape_when_mouse_up') -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end) diff --git a/main.lua b/main.lua index b166ac4..0446825 100644 --- a/main.lua +++ b/main.lua @@ -533,11 +533,6 @@ function App.keychord_pressed(chord, key) record_undo_event({before=before, after=snapshot(drawing_index)}) schedule_save() end - elseif chord == 'escape' and App.mouse_down(1) then - local _,drawing = Drawing.current_drawing() - if drawing then - drawing.pending = {} - end elseif chord == 'escape' and not App.mouse_down(1) then for _,line in ipairs(Lines) do if line.mode == 'drawing' then |