diff options
-rw-r--r-- | main.lua | 8 | ||||
-rw-r--r-- | text.lua | 2 | ||||
-rw-r--r-- | text_tests.lua | 18 |
3 files changed, 27 insertions, 1 deletions
diff --git a/main.lua b/main.lua index e5dde61..2ad8c76 100644 --- a/main.lua +++ b/main.lua @@ -347,6 +347,7 @@ function App.mousepressed(x,y, mouse_button) Old_selection1 = Selection1 Mousepress_shift = App.shift_down() Selection1 = {line=line_index, pos=Text.to_pos_on_line(line, x, y)} +--? print('selection') end elseif line.mode == 'drawing' then if Drawing.in_drawing(line, x, y) then @@ -372,6 +373,7 @@ function App.mousereleased(x,y, button) for line_index,line in ipairs(Lines) do if line.mode == 'text' then if Text.in_line(line_index,line, x,y) then +--? print('reset selection') Cursor1 = {line=line_index, pos=Text.to_pos_on_line(line, x, y)} --? print(Cursor1.line, Cursor1.pos) if Mousepress_shift then @@ -405,6 +407,9 @@ function App.textinput(t) Text.textinput(t) end schedule_save() + if not App.shift_down() then + Selection1 = {} + end end function App.keychord_pressed(chord) @@ -547,6 +552,9 @@ function App.keychord_pressed(chord) for _,line in ipairs(Lines) do line.y = nil end -- just in case we scroll Text.keychord_pressed(chord) end + if not App.shift_down() then + Selection1 = {} + end end function App.keyreleased(key, scancode) diff --git a/text.lua b/text.lua index 80cefaa..f7f2e80 100644 --- a/text.lua +++ b/text.lua @@ -164,7 +164,7 @@ end -- Don't handle any keys here that would trigger love.textinput above. function Text.keychord_pressed(chord) ---? print('chord') +--? print('chord', chord, Selection1.line, Selection1.pos) --== shortcuts that mutate text if chord == 'return' then local before_line = Cursor1.line diff --git a/text_tests.lua b/text_tests.lua index 221d969..f835d8d 100644 --- a/text_tests.lua +++ b/text_tests.lua @@ -186,6 +186,24 @@ function test_click_on_wrapping_line_containing_non_ascii() check_eq(Cursor1.pos, 15, 'F - test_click_on_wrapping_line_containing_non_ascii/cursor') -- one more than the number of UTF-8 code-points end +function test_edit_after_click_resets_selection() + io.write('\ntest_edit_after_click_resets_selection') + -- display a line of text + App.screen.init{width=80, height=80} + Lines = load_array{'abc'} + Line_width = 75 + Cursor1 = {line=1, pos=1} + Screen_top1 = {line=1, pos=1} + Screen_bottom1 = {} + App.draw() + -- click past the end of it and hit enter + App.run_after_mouse_click(Margin_left+40,Margin_top+5, 1) + check(Selection1.line, 'F - test_edit_after_click_resets_selection/baseline') + App.run_after_keychord('return') + -- selection is reset since shift key is not pressed + check_nil(Selection1.line, 'F - test_edit_after_click_resets_selection') +end + function test_edit_wrapping_text() io.write('\ntest_edit_wrapping_text') App.screen.init{width=50, height=60} |