bugfix: inscript's bug

[?]
Jun 4, 2023, 7:20 PM
6XCJX4DZB6UEAXEXXUGVVPBCF5SNDYOJGU3Q6BPB4ZMI5DZH4MYQC

Dependencies

  • [2] KYNGDE2C consistent names in a few more places
  • [3] YFW4MNNP handle wrapping lines
  • [4] 3OTESDW6 move drawing.starty into line cache
  • [5] S2MISTTM add state arg to a few functions
  • [6] UHB4GARJ left/right margin -> left/right coordinates
  • [7] FKNXK2OA switch to line index in a function
  • [8] MTJEVRJR add state arg to a few functions
  • [9] WJBZZQE4 fold together two largely similar cases
  • [10] HIKLULFQ extract a function
  • [11] 52ZZ5TIE switch to line index in a function
  • [12] 4CXVIEBS add args to some functions
  • [13] BW2IUB3K keep all text cache writes inside text.lua
  • [14] 6RYLD5ON change how we handle clicks above top margin
  • [15] LXTTOB33 extract a couple of files
  • [16] OI4FPFIN support drawings in the source editor
  • [17] QCPXQ2E3 add state arg to a few functions
  • [18] 2L5MEZV3 experiment: new edit namespace
  • [19] PK5U572C drop some extra args
  • [20] 7FPELAZB ah, I see the problem
  • [21] KTZQ57HV replace globals with args in a few functions
  • [22] LF7BWEG4 group all editor globals
  • [23] 4EGQRXDA bugfix: naming points
  • [24] 2CK5QI7W make love event names consistent
  • [25] GNKUD23I get rid of recent_mouse
  • [26] MXA3RZYK deduce left/right from state where possible
  • [27] 4GYPLUDY streamline the interface for Text.draw
  • [28] LNUHQOGH start passing in Editor_state explicitly
  • [29] MRA2Y3EE idea: set recent_mouse on mouse events
  • [30] QJISOCHJ some temporary logging to catch a bug
  • [31] FHSZYAZ2 more precise search highlighting
  • [32] DLQAEAC7 add state arg to Drawing.mouse_pressed
  • [33] K6DTOGOQ flip return value of button handlers
  • [34] GFXWHTE6 mouse wheel support
  • [35] 6D5MOJS4 allow buttons to interrupt events
  • [*] WAR3HXHT test both ways of selecting text with mouse
  • [*] BULPIBEG beginnings of a module for the text editor
  • [*] SVJZZDC3 snapshot - no, that's all wrong
  • [*] GNQC72UX generalize a function
  • [*] HYEAFRZ2 split mouse_pressed events between Text and Drawing
  • [*] OP643FFG move

Change contents

  • edit in text_tests.lua at line 867
    [3.766]
    [37.543]
    function test_select_text_using_mouse_starting_below_text()
    -- I'd like to test what happens when a mouse click is below some page of
    -- text, potentially even in the middle of a line.
    -- However, it's brittle to set up a text line boundary just right.
    -- So I'm going to just check things below the bottom of the final line of
    -- text when it's in the middle of the screen.
    -- final screen line ends in the middle of screen
    App.screen.init{width=50, height=60}
    Editor_state = edit.initialize_test_state()
    Editor_state.lines = load_array{'abcde'}
    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)
    local y = Editor_state.top
    App.screen.check(y, 'ab', 'baseline:screen:1')
    y = y + Editor_state.line_height
    App.screen.check(y, 'cde', 'baseline:screen:2')
    -- press mouse above first line of text
    edit.run_after_mouse_press(Editor_state, 5,App.screen.height-5, 1)
    -- selection is past bottom-most text in screen
    check(Editor_state.selection1.line ~= nil, 'selection:line-not-nil')
    check_eq(Editor_state.selection1.line, 1, 'selection:line')
    check_eq(Editor_state.selection1.pos, 6, 'selection:pos')
    end
  • edit in text.lua at line 594
    [39.1332]
    [40.298]
    -- result: pos, index of screen line
  • edit in text.lua at line 607
    [41.6]
    [4.2443]
    function Text.pos_at_end_of_screen_line(State, loc1)
    Text.populate_screen_line_starting_pos(State, loc1.line)
    local line_cache = State.line_cache[loc1.line]
    local most_recent_final_pos = utf8.len(State.lines[loc1.line].data)+1
    for i=#line_cache.screen_line_starting_pos,1,-1 do
    local spos = line_cache.screen_line_starting_pos[i]
    if spos <= loc1.pos then
    return most_recent_final_pos
    end
    most_recent_final_pos = spos-1
    end
    assert(false)
    end
  • edit in select.lua at line 70
    [4.45814][4.45814:45876]()
    -- inefficient for some reason, so don't do it on every frame
  • replacement in select.lua at line 71
    [4.136][4.4079:4147](),[4.1228][4.4079:4147](),[4.4147][4.1096:1115](),[4.1115][4.46270:46275](),[4.1436][4.46270:46275](),[4.79554][4.46270:46275](),[4.46270][4.46270:46275](),[4.46275][4.4148:4181]()
    local line,pos = Text.to_pos(State, App.mouse_x(), App.mouse_y())
    return line, pos
    end
    function Text.to_pos(State, x,y)
    [4.4078]
    [4.909]
    local x,y = App.mouse_x(), App.mouse_y()
  • edit in select.lua at line 82
    [4.46495]
    [42.5]
    return State.screen_bottom1.line, Text.pos_at_end_of_screen_line(State, State.screen_bottom1)
  • edit in edit.lua at line 155
    [4.22445]
    [4.4101]
    local screen_bottom1 = {line=nil, pos=nil}
  • replacement in edit.lua at line 161
    [4.3095][4.25185:25239]()
    State.screen_bottom1 = {line=line_index, pos=nil}
    [4.3095]
    [4.15]
    screen_bottom1.line = line_index
  • replacement in edit.lua at line 184
    [4.5239][4.341:419]()
    y, State.screen_bottom1.pos = Text.draw(State, line_index, y, startpos)
    [4.5239]
    [4.1039]
    y, screen_bottom1.pos = Text.draw(State, line_index, y, startpos)
  • edit in edit.lua at line 195
    [4.5923]
    [4.4191]
    State.screen_bottom1 = screen_bottom1
  • replacement in edit.lua at line 226
    [4.4581][4.152:253]()
    print_and_log(('edit.mouse_press: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))
    [4.4581]
    [4.15]
    --? print_and_log(('edit.mouse_press: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))
  • replacement in edit.lua at line 263
    [4.254][4.8026:8040](),[4.447][4.8026:8040](),[4.691][4.8026:8040](),[4.5144][4.8026:8040](),[4.100956][4.8026:8040](),[4.8026][4.8026:8040]()
    break
    [4.7962]
    [4.8040]
    return
  • replacement in edit.lua at line 272
    [4.77][4.8321:8335](),[4.261][4.8321:8335](),[2.788][4.8321:8335](),[4.8321][4.8321:8335]()
    break
    [2.788]
    [4.8335]
    return
  • edit in edit.lua at line 276
    [4.8359]
    [4.8359]
    -- still here? click is below all screen lines
    State.old_cursor1 = State.cursor1
    State.old_selection1 = State.selection1
    State.mousepress_shift = App.shift_down()
    State.selection1 = {
    line=State.screen_bottom1.line,
    pos=Text.pos_at_end_of_screen_line(State, State.screen_bottom1),
    }
  • replacement in edit.lua at line 289
    [4.5338][4.448:551]()
    print_and_log(('edit.mouse_release: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))
    [4.5338]
    [4.5339]
    --? print_and_log(('edit.mouse_release: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))
  • replacement in edit.lua at line 298
    [4.8804][4.796:856]()
    print_and_log('edit.mouse_release: no current drawing')
    [4.8804]
    [4.5479]
    --? print_and_log('edit.mouse_release: no current drawing')
  • replacement in edit.lua at line 302
    [4.258][4.552:631]()
    print_and_log(('edit.mouse_release: in line %d'):format(line_index))
    [4.258]
    [4.5627]
    --? print_and_log(('edit.mouse_release: in line %d'):format(line_index))
  • replacement in edit.lua at line 307
    [4.9165][4.632:744]()
    print_and_log(('edit.mouse_release: cursor now %d,%d'):format(State.cursor1.line, State.cursor1.pos))
    [4.9165]
    [4.5833]
    --? print_and_log(('edit.mouse_release: cursor now %d,%d'):format(State.cursor1.line, State.cursor1.pos))
  • replacement in edit.lua at line 323
    [4.9624][4.745:936]()
    print_and_log(('edit.mouse_release: finally selection %s,%s cursor %d,%d'):format(tostring(State.selection1.line), tostring(State.selection1.pos), State.cursor1.line, State.cursor1.pos))
    [4.9624]
    [4.1864]
    --? print_and_log(('edit.mouse_release: finally selection %s,%s cursor %d,%d'):format(tostring(State.selection1.line), tostring(State.selection1.pos), State.cursor1.line, State.cursor1.pos))