select text using mouse drag

Doesn't yet highlight while dragging.
This commit is contained in:
Kartik K. Agaram 2022-06-03 08:11:18 -07:00
parent 9efeae1f82
commit 73cc12047e
3 changed files with 27 additions and 12 deletions

View File

@ -204,6 +204,12 @@ function App.run_after_mousepress(x,y, button)
App.draw()
end
function App.run_after_mouserelease(x,y, button)
App.mousereleased(x,y, button)
App.screen.contents = {}
App.draw()
end
function App.screen.check(y, expected_contents, msg)
--? print('checking for "'..expected_contents..'" at y '..tostring(y))
local screen_row = 'y'..tostring(y)

View File

@ -198,16 +198,8 @@ function App.mousepressed(x,y, mouse_button)
for line_index,line in ipairs(Lines) do
if line.mode == 'text' then
if Text.in_line(line, x,y) then
if love.keyboard.isDown('lshift') or love.keyboard.isDown('rshift') then
if Selection1.line == nil then
Selection1 = {line=Cursor1.line, pos=Cursor1.pos}
end
else
if Selection1.line then
Selection1 = {}
end
end
Text.move_cursor(line_index, line, x, y)
Selection1 = {line=Cursor1.line, pos=Cursor1.pos}
end
elseif line.mode == 'drawing' then
if Drawing.in_drawing(line, x, y) then
@ -219,7 +211,20 @@ end
function App.mousereleased(x,y, button)
if Search_term then return end
Drawing.mouse_released(x,y, button)
if Lines.current_drawing then
Drawing.mouse_released(x,y, button)
else
for line_index,line in ipairs(Lines) do
if line.mode == 'text' then
if Text.in_line(line, x,y) then
Text.move_cursor(line_index, line, x, y)
if Text.eq1(Cursor1, Selection1) then
Selection1 = {}
end
end
end
end
end
end
function App.textinput(t)

View File

@ -499,7 +499,7 @@ function test_move_cursor_using_mouse()
Screen_bottom1 = {}
App.draw() -- populate line.y for each line in Lines
local screen_left_margin = 25 -- pixels
App.run_after_mousepress(screen_left_margin+8,Margin_top+5, '1')
App.run_after_mouserelease(screen_left_margin+8,Margin_top+5, '1')
check_eq(Cursor1.line, 1, 'F - test_move_cursor_using_mouse/cursor:line')
check_eq(Cursor1.pos, 2, 'F - test_move_cursor_using_mouse/cursor:pos')
end
@ -1039,7 +1039,7 @@ function test_position_cursor_on_recently_edited_wrapping_line()
App.screen.check(y, 'stu', 'F - test_position_cursor_on_recently_edited_wrapping_line/baseline2/screen:3')
-- try to move the cursor earlier in the third screen line by clicking the mouse
local screen_left_margin = 25 -- pixels
App.run_after_mousepress(screen_left_margin+8,Margin_top+Line_height*2+5, '1')
App.run_after_mouserelease(screen_left_margin+8,Margin_top+Line_height*2+5, '1')
-- cursor should move
check_eq(Cursor1.line, 1, 'F - test_move_cursor_using_mouse/cursor:line')
check_eq(Cursor1.pos, 26, 'F - test_move_cursor_using_mouse/cursor:pos')
@ -1980,6 +1980,10 @@ function Text.to1(pos2)
return result
end
function Text.eq1(a, b)
return a.line == b.line and a.pos == b.pos
end
function Text.lt1(a, b)
if a.line < b.line then
return true