fix a crash involving mouse and drawings

akkartik
Jun 9, 2024, 9:14 PM
QAMVLUK22RP5RBDTDV5XVPQCSJUWDWESV4TRCUTNUM46E26BH2AQC

Dependencies

  • [2] 656FM555 bugfix: clear selection when clicking above or below lines
  • [3] UHB4GARJ left/right margin -> left/right coordinates
  • [4] 2L5MEZV3 experiment: new edit namespace
  • [5] 7CLGG7J2 test: autosave after any shape
  • [6] LF7BWEG4 group all editor globals
  • [7] DSLD74DK lots more tests
  • [8] 6XCJX4DZ bugfix: inscript's bug
  • [9] CNCYMM6A make test initializations a little more obvious
  • [10] ORRSP7FV deduce test names on failures
  • [11] ILOA5BYF separate data structure for each line's cache data
  • [*] LXTTOB33 extract a couple of files
  • [*] BULPIBEG beginnings of a module for the text editor
  • [*] MXA3RZYK deduce left/right from state where possible
  • [*] TGHAJBES use line cache for drawings as well
  • [*] WJBZZQE4 fold together two largely similar cases
  • [*] KYNGDE2C consistent names in a few more places
  • [*] 5UKUADTW distinguish consistently between mouse buttons and other buttons
  • [*] K2X6G75Z start writing some tests for drawings
  • [*] FS2ITYYH record a known issue
  • [*] IDGP4BJZ new known issue with drawings
  • [*] ZTMRQZSW Readme

Change contents

  • replacement in text_tests.lua at line 19
    [3.564][3.564:604]()
    App.screen.init{width=120, height=60}
    [3.519]
    [3.49]
    App.screen.init{width=800, height=600}
  • edit in text.lua at line 624
    [3.1362]
    [3.1362]
    assert(State.lines[loc1.line].mode == 'text')
  • edit in text.lua at line 638
    [3.1785]
    [15.2443]
    function Text.final_text_loc_on_screen(State)
    if State.lines[State.screen_bottom1.line].mode == 'text' then
    return {
    line=State.screen_bottom1.line,
    pos=Text.pos_at_end_of_screen_line(State, State.screen_bottom1),
    }
    end
    local loc2 = Text.to2(State, State.screen_bottom1)
    while true do
    if State.lines[loc2.line].mode == 'text' then break end
    assert(loc2.line > 1 or loc2.screen_line > 1 and loc2.screen_pos > 1) -- elsewhere we're making sure there's always at least one text line on screen
    loc2 = Text.previous_screen_line(State, loc2)
    end
    local result = Text.to1(State, loc2)
    result.pos = Text.pos_at_end_of_screen_line(State, result)
    return result
    end
  • edit in edit.lua at line 69
    [3.96483]
    [3.96483]
    --
    -- On lines that are drawings, pos will be nil.
  • replacement in edit.lua at line 72
    [3.96572][3.96572:96626]()
    cursor1 = {line=1, pos=1}, -- position of cursor
    [3.96572]
    [3.96626]
    cursor1 = {line=1, pos=1}, -- position of cursor; must be on a text line
  • edit in edit.lua at line 190
    [16.1966]
    [17.609]
    for _,line_cache in ipairs(State.line_cache) do line_cache.starty = nil end
  • replacement in edit.lua at line 298
    [3.2459][3.2459:2595]()
    State.selection1 = {
    line=State.screen_bottom1.line,
    pos=Text.pos_at_end_of_screen_line(State, State.screen_bottom1),
    }
    [3.2459]
    [3.8359]
    State.selection1 = Text.final_text_loc_on_screen(State)
  • replacement in edit.lua at line 336
    [2.3196][2.3196:3327]()
    State.cursor1.line, State.cursor1.pos = State.screen_bottom1.line, Text.pos_at_end_of_screen_line(State, State.screen_bottom1)
    [2.3196]
    [2.3327]
    State.cursor1 = Text.final_text_loc_on_screen(State)
  • edit in edit.lua at line 599
    [18.834]
    [19.166]
    edit.draw(State)
  • replacement in drawing_tests.lua at line 6
    [3.146][3.146:186]()
    App.screen.init{width=120, height=60}
    [3.102]
    [3.5731]
    App.screen.init{width=800, height=600}
  • edit in README.md at line 75
    [22.204]
    [23.90]
    * If you ever see a crash when clicking on the mouse, it might be because a
    mouse press and release need to happen in separate frames. Try pressing and
    releasing more slowly and let me know if that helps or not. This is klunky,
    sorry.