get rid of recent_mouse

[?]
Jun 2, 2023, 5:12 AM
GNKUD23IHHTLV6COIR4LBK36GPN2FPBGSXHOSJHRW5KKEA2ENWUAC

Dependencies

  • [2] MRA2Y3EE idea: set recent_mouse on mouse events
  • [3] 7RKFA3VA failing test now looks realistic
  • [4] MXA3RZYK deduce left/right from state where possible
  • [5] QCPXQ2E3 add state arg to a few functions
  • [6] LF7BWEG4 group all editor globals
  • [7] 2L5MEZV3 experiment: new edit namespace
  • [8] QJISOCHJ some temporary logging to catch a bug
  • [9] 4CXVIEBS add args to some functions
  • [10] VSBSWTE4 bugfix: where cursor is drawn
  • [11] WAR3HXHT test both ways of selecting text with mouse
  • [12] LAW2O3NW extract variable Margin_left
  • [13] S2MISTTM add state arg to a few functions
  • [14] UHB4GARJ left/right margin -> left/right coordinates
  • [15] ORRSP7FV deduce test names on failures
  • [16] LXTTOB33 extract a couple of files
  • [17] DRFE3B3Z mouse buttons are integers, not strings
  • [18] ZLJGZYQG select text with shift + mouseclick
  • [19] PK5U572C drop some extra args
  • [20] FKNXK2OA switch to line index in a function
  • [21] T3B4NLV3 include a unit test
  • [22] 356GY7IQ unify two similar functions
  • [23] 7FPELAZB ah, I see the problem
  • [24] 3TCZ7ADH move
  • [25] JFFUF5AL override mouse state lookups in tests
  • [26] RMKMPFT5 fix a corner case when selecting text
  • [27] LNUHQOGH start passing in Editor_state explicitly

Change contents

  • replacement in text_tests.lua at line 907
    [3.802][3.802:1788](),[4.323][4.6250:6254](),[4.842][4.6250:6254](),[4.842][4.6250:6254](),[4.1306][4.6250:6254](),[4.1313][4.6250:6254](),[4.1581][4.6250:6254](),[3.1788][4.6250:6254](),[4.7365][4.6250:6254](),[4.23358][4.6250:6254](),[4.6250][4.6250:6254]()
    function test_select_all_text_then_mouse_press_outside_text()
    -- display a single line of text
    App.screen.init{width=75, height=80}
    Editor_state = edit.initialize_test_state()
    Editor_state.lines = load_array{'abc def'}
    Text.redraw_all(Editor_state)
    Editor_state.cursor1 = {line=1, pos=1}
    Editor_state.screen_top1 = {line=1, pos=1}
    Editor_state.screen_bottom1 = {}
    edit.draw(Editor_state)
    -- select all
    App.fake_key_press('lctrl')
    edit.run_after_keychord(Editor_state, 'C-a')
    App.fake_key_release('lctrl')
    edit.key_release(Editor_state, 'lctrl')
    -- selection
    check_eq(Editor_state.selection1.line, 1, 'selection:line')
    check_eq(Editor_state.selection1.pos, 1, 'selection:pos')
    check_eq(Editor_state.cursor1.line, 1, 'cursor:line')
    check_eq(Editor_state.cursor1.pos, 8, 'cursor:pos')
    -- part of a mouse click outside the selected line
    edit.run_after_mouse_press(Editor_state, 45, Margin_top + Editor_state.line_height + 10, --[[mouse button]] 1)
    end
    [3.802]
    [4.6254]
    --? function test_select_all_text_then_mouse_press_outside_text()
    --? -- display a single line of text
    --? App.screen.init{width=75, height=80}
    --? Editor_state = edit.initialize_test_state()
    --? Editor_state.lines = load_array{'abc def'}
    --? Text.redraw_all(Editor_state)
    --? Editor_state.cursor1 = {line=1, pos=1}
    --? Editor_state.screen_top1 = {line=1, pos=1}
    --? Editor_state.screen_bottom1 = {}
    --? edit.draw(Editor_state)
    --? -- select all
    --? App.fake_key_press('lctrl')
    --? edit.run_after_keychord(Editor_state, 'C-a')
    --? App.fake_key_release('lctrl')
    --? edit.key_release(Editor_state, 'lctrl')
    --? -- selection
    --? check_eq(Editor_state.selection1.line, 1, 'selection:line')
    --? check_eq(Editor_state.selection1.pos, 1, 'selection:pos')
    --? check_eq(Editor_state.cursor1.line, 1, 'cursor:line')
    --? check_eq(Editor_state.cursor1.pos, 8, 'cursor:pos')
    --? -- part of a mouse click outside the selected line
    --? edit.run_after_mouse_press(Editor_state, 45, Margin_top + Editor_state.line_height + 10, --[[mouse button]] 1)
    --? end
  • edit in select.lua at line 72
    [4.4078][2.13:94](),[2.94][4.13:137](),[4.1135][4.13:137](),[4.137][4.1135:1194](),[4.1135][4.1135:1194](),[4.1194][4.46046:46052](),[4.79358][4.46046:46052](),[4.46046][4.46046:46052](),[4.46052][2.95:136]()
    if State.recent_mouse.time and State.recent_mouse.time > Current_time-0.1 then
    print_and_log(('text.mouse_pos: returning recent value %d,%d'):format(State.recent_mouse.line, State.recent_mouse.pos))
    return State.recent_mouse.line, State.recent_mouse.pos
    end
    State.recent_mouse.time = Current_time
  • replacement in select.lua at line 73
    [4.463][4.46148:46163](),[4.1309][4.46148:46163](),[4.1343][4.46148:46163](),[4.4147][4.46148:46163](),[4.46148][4.46148:46163](),[4.46163][4.1310:1378](),[4.1378][4.46219:46225](),[4.79482][4.46219:46225](),[4.46219][4.46219:46225](),[4.46225][4.1379:1436]()
    if line then
    State.recent_mouse.line = line
    State.recent_mouse.pos = pos
    end
    return State.recent_mouse.line, State.recent_mouse.pos
    [4.4147]
    [4.46270]
    return line, pos
  • edit in edit.lua at line 78
    [4.96897][4.96897:96999]()
    -- when selecting text, avoid recomputing some state on every single frame
    recent_mouse = {},
  • edit in edit.lua at line 250
    [4.7962][2.151:254]()
    State.recent_mouse = {time=Current_time, line=State.selection1.line, pos=State.selection1.pos}
  • edit in edit.lua at line 286
    [4.744][2.255:354]()
    State.recent_mouse = {time=Current_time, line=State.cursor1.line, pos=State.cursor1.pos}