fix a corner case when selecting text

[?]
Jun 9, 2022, 10:49 PM
RMKMPFT5L67WIFWIO4GTC6XESX6UPKNL4GPNQLOBC5CXSUZABEHQC

Dependencies

  • [2] QZH3PQFU .
  • [3] 3TCZ7ADH move
  • [4] ZLJGZYQG select text with shift + mouseclick
  • [5] 2INHXC3K position cursor by clicking on text
  • [6] HYEAFRZ2 split mouse_pressed events between Text and Drawing
  • [7] 5FW7YOFT highlight selection while dragging
  • [8] BOFNXP5G clicking now moves the cursor even on long, wrapped lines
  • [9] 2ENZW7TV select text using mouse drag
  • [10] DHI6IJCN selecting text and deleting selections
  • [*] LXTTOB33 extract a couple of files
  • [*] OTIBCAUJ love2d scaffold

Change contents

  • edit in text_tests.lua at line 225
    [3.323]
    [12.6250]
    end
    function test_select_text_repeatedly_using_mouse_and_shift()
    io.write('\ntest_select_text_repeatedly_using_mouse_and_shift')
    App.screen.init{width=50, height=60}
    Lines = load_array{'abc', 'def', 'xyz'}
    Line_width = App.screen.width
    Cursor1 = {line=1, pos=1}
    Screen_top1 = {line=1, pos=1}
    Screen_bottom1 = {}
    Selection1 = {}
    App.draw() -- populate line.y for each line in Lines
    local screen_left_margin = 25 -- pixels
    -- click on first location
    App.run_after_mousepress(screen_left_margin+8,Margin_top+5, '1')
    App.run_after_mouserelease(screen_left_margin+8,Margin_top+5, '1')
    -- hold down shift and click on a second location
    App.keypress('lshift')
    App.run_after_mousepress(screen_left_margin+20,Margin_top+5, '1')
    App.run_after_mouserelease(screen_left_margin+20,Margin_top+Line_height+5, '1')
    -- hold down shift and click at a third location
    App.keypress('lshift')
    App.run_after_mousepress(screen_left_margin+20,Margin_top+5, '1')
    App.run_after_mouserelease(screen_left_margin+8,Margin_top+Line_height+5, '1')
    App.keyrelease('lshift')
    -- selection is between first and third location. forget the second location, not the first.
    check_eq(Selection1.line, 1, 'F - test_select_text_repeatedly_using_mouse_and_shift/selection:line')
    check_eq(Selection1.pos, 2, 'F - test_select_text_repeatedly_using_mouse_and_shift/selection:pos')
    check_eq(Cursor1.line, 2, 'F - test_select_text_repeatedly_using_mouse_and_shift/cursor:line')
    check_eq(Cursor1.pos, 2, 'F - test_select_text_repeatedly_using_mouse_and_shift/cursor:pos')
  • edit in main.lua at line 58
    [4.10940]
    [4.1391]
    Old_cursor1, Old_selection1, Mousepress_shift = nil -- some extra state to compute selection between mousepress and mouserelease
  • replacement in main.lua at line 275
    [4.492][4.1313:1418](),[4.1418][2.8:81](),[2.81][4.1419:1528](),[4.1574][4.1419:1528]()
    if App.shift_down() then
    Selection1 = {line=Cursor1.line, pos=Cursor1.pos}
    end
    Cursor1 = {line=line_index, pos=Text.to_pos_on_line(line, x, y)}
    if not App.shift_down() then
    Selection1 = {line=Cursor1.line, pos=Cursor1.pos}
    end
    [4.492]
    [4.361]
    -- delicate dance between cursor, selection and old cursor
    -- manual tests:
    -- regular press+release: sets cursor, clears selection
    -- shift press+release:
    -- sets selection to old cursor if not set otherwise leaves it untouched
    -- sets cursor
    -- press and hold to start a selection: sets selection on press, cursor on release
    -- press and hold, then press shift: ignore shift
    -- i.e. mousereleased should never look at shift state
    Old_cursor1 = Cursor1
    Old_selection1 = Selection1
    Mousepress_shift = App.shift_down()
    Selection1 = {line=line_index, pos=Text.to_pos_on_line(line, x, y)}
  • replacement in main.lua at line 306
    [2.157][4.1529:1602](),[4.1667][4.1529:1602](),[4.1602][4.589:617](),[4.589][4.589:617]()
    if Text.eq1(Cursor1, Selection1) and not App.shift_down() then
    Selection1 = {}
    [2.157]
    [4.617]
    if Mousepress_shift then
    if Old_selection1.line == nil then
    Selection1 = Old_cursor1
    else
    Selection1 = Old_selection1
    end
  • edit in main.lua at line 313
    [4.631]
    [4.631]
    Old_cursor1, Old_selection1, Mousepress_shift = nil