clicking now moves the cursor even on long, wrapped lines

[?]
May 20, 2022, 5:07 AM
BOFNXP5GZDCUMQG3LQVTSSFEQP7REQ4RIRJLDLETFSAGFTVDVEKAC

Dependencies

  • [2] DXT4QTAH a few more integer coordinates
  • [3] DAENUOGV eliminate assumptions that line length == size in bytes
  • [4] PHQPLJUQ rename
  • [5] DLQMM265 scroll past first page
  • [6] LUNH47XX make text and drawings the same width
  • [7] 4C375P53 this is a bit clearer
  • [8] BULPIBEG beginnings of a module for the text editor
  • [9] B3IWYWSR delete another arg that can be deduced
  • [10] UWNHC4AA redo y computations
  • [11] HYEAFRZ2 split mouse_pressed events between Text and Drawing
  • [12] H2DPLWMV snapshot: wrapping long lines at word boundaries
  • [13] 2INHXC3K position cursor by clicking on text
  • [14] HIH47LNB drop unused arg
  • [*] OTIBCAUJ love2d scaffold
  • [*] VVXVV2D2 change data model; text can now have metadata
  • [*] JCSLDGAH beginnings of support for multiple shapes

Change contents

  • edit in text.lua at line 42
    [5.1642][3.1:113]()
    --? love.graphics.setColor(0.75,0.75,0.75)
    --? love.graphics.line(line_width, 0, line_width, Screen_height)
  • edit in text.lua at line 58
    [5.2198]
    [5.2198]
    if line.screen_line_starting_pos == nil then
    line.screen_line_starting_pos = {1, pos}
    else
    table.insert(line.screen_line_starting_pos, pos)
    end
  • replacement in text.lua at line 273
    [5.433][2.139:209]()
    return x >= 16 and y >= line.y and y < line.y + math.floor(15*Zoom)
    [5.433]
    [5.95]
    if x < 16 then return false end
    if y < line.y then return false end
    if line.screen_line_starting_pos == nil then return y < line.y + math.floor(15*Zoom) end
    return y < line.y + #line.screen_line_starting_pos * math.floor(15*Zoom)
  • replacement in text.lua at line 279
    [5.100][4.1:49]()
    function Text.move_cursor(line_index, line, mx)
    [5.100]
    [5.153]
    function Text.move_cursor(line_index, line, mx, my)
  • replacement in text.lua at line 281
    [5.180][4.50:104]()
    Cursor_pos = Text.nearest_cursor_pos(line.data, mx)
    [5.180]
    [5.464]
    if line.screen_line_starting_pos == nil then
    --? print('single screen line')
    Cursor_pos = Text.nearest_cursor_pos(line.data, mx)
    return
    end
    assert(line.fragments)
    assert(my >= line.y)
    --? print('move_cursor', mx, my)
    if my < line.y + math.floor(15*Zoom) then
    --? print('first screen line')
    Cursor_pos = Text.nearest_cursor_pos(line.data, mx)
    return
    end
    -- duplicate some logic from Text.draw
    local y = line.y
    for _,screen_line_starting_pos in ipairs(line.screen_line_starting_pos) do
    --? print('screen line:', screen_line_starting_pos)
    local nexty = y + math.floor(15*Zoom)
    if my < nexty then
    local s = string.sub(line.data, screen_line_starting_pos)
    Cursor_pos = screen_line_starting_pos + Text.nearest_cursor_pos(s, mx) - 1
    return
    end
    y = nexty
    end
    assert(false)
  • edit in text.lua at line 308
    [5.468]
    [5.468]
    -- manual test:
    -- line: abc
    -- def
    -- gh
    -- fragments: abc, def, gh
    -- click inside e
    -- line_starting_pos = 1 + 3 = 4
    -- nearest_cursor_pos('defgh', mx) = 2
    -- Cursor_pos = 4 + 2 - 1 = 5
    -- manual test:
    -- click inside h
    -- line_starting_pos = 1 + 3 + 3 = 7
    -- nearest_cursor_pos('gh', mx) = 2
    -- Cursor_pos = 7 + 2 - 1 = 8
  • edit in main.lua at line 15
    [17.104]
    [18.104]
    -- screen_line_starting_pos: optional array of grapheme indices if it wraps over more than one screen line
  • edit in main.lua at line 130
    [5.213][3.521:595]()
    --? y = Text.draw(line, 100, line_index, Cursor_line, Cursor_pos)
  • replacement in main.lua at line 148
    [5.492][5.492:538]()
    Text.move_cursor(line_index, line, x)
    [5.492]
    [5.361]
    Text.move_cursor(line_index, line, x, y)