left/right cursor movement, deleting characters

[?]
May 17, 2022, 3:16 AM
IYW7X3WLOPYLSNO5IQNSULUNO4XFEM24DJ2VB5HPBUKWUYFPRCGQC

Dependencies

  • [2] OFA3PRBS autosave on keystrokes
  • [3] NCRKBTHC position cursor more precisely
  • [4] XX7G2FFJ intermingle freehand line drawings with text
  • [5] 6PUNJS5B backspace
  • [6] JCSLDGAH beginnings of support for multiple shapes
  • [7] GVOFXXIT delete drawing using backspace
  • [8] QW5KQQTD fix a comment
  • [9] NL5J7Z5H new mode: polygon
  • [10] 7Q4B6M2D esc to cancel a shape mid-click
  • [11] 6LJZN727 handle chords
  • [12] KCIM5UTV revert: back to freehand
  • [13] ZOOY3ME4 new mode: circle arc
  • [14] 2C7CTIQY make space for multiple kinds of width
  • [15] YKRF5V3Z starting to load/save
  • [16] QU7NHFOV show cursor
  • [17] G77XIN7M selecting a stroke
  • [18] WAZVXUV2 simplest possible way to straighten strokes
  • [19] OTIBCAUJ love2d scaffold
  • [20] 7RN3AETY bugfix: text sometimes getting colored like drawing borders
  • [21] VXORMHME delete experimental REPL
  • [22] 3XD6M3CF refactor
  • [23] MNWHXPBL more lightweight; select just the stroke at the mouse
  • [24] HWPK4SMP new mode: manhattan
  • [25] H7OEU6WP experimental approach to combining keyboard and mouse while drawing

Change contents

  • replacement in main.lua at line 31
    [4.22][4.3:14](),[4.1237][4.3:14](),[4.2][4.3:14]()
    lines = {}
    [4.1237]
    [4.1238]
    lines = {''}
    cursor_line = 1
    -- this is a line
    -- ^cursor_pos = 1
    -- ^cursor_pos = 2
    -- ...
    -- ^cursor_pos past end of line is 15
    cursor_pos = #lines[cursor_line]+1
  • replacement in main.lua at line 162
    [4.71][3.1:127]()
    love.graphics.print('_', 25+text:getWidth()*1.5, y+6) -- drop the cursor down a bit to account for the increased font size
    [4.71]
    [4.416]
    local line_before_cursor = lines[cursor_line]:sub(1, cursor_pos-1)
    local text_before_cursor = love.graphics.newText(love.graphics.getFont(), line_before_cursor)
    love.graphics.print('_', 25+text_before_cursor:getWidth()*1.5, y+6) -- drop the cursor down a bit to account for the increased font size
  • replacement in main.lua at line 496
    [4.81][4.50:85](),[4.50][4.50:85]()
    lines[#lines] = lines[#lines]..t
    [4.81]
    [2.62]
    local byteoffset
    if cursor_pos > 1 then
    byteoffset = utf8.offset(lines[cursor_line], cursor_pos-1)
    else
    byteoffset = 0
    end
    lines[cursor_line] = string.sub(lines[cursor_line], 1, byteoffset)..t..string.sub(lines[cursor_line], byteoffset+1)
    cursor_pos = cursor_pos+1
  • replacement in main.lua at line 519
    [4.148][4.148:296]()
    local byteoffset = utf8.offset(lines[#lines], -1)
    if byteoffset then
    lines[#lines] = string.sub(lines[#lines], 1, byteoffset-1)
    [4.148]
    [4.296]
    if cursor_pos > 1 then
    local byte_start = utf8.offset(lines[cursor_line], cursor_pos-1)
    local byte_end = utf8.offset(lines[cursor_line], cursor_pos)
    if byte_start then
    if byte_end then
    lines[cursor_line] = string.sub(lines[cursor_line], 1, byte_start-1)..string.sub(lines[cursor_line], byte_end)
    else
    lines[cursor_line] = string.sub(lines[cursor_line], 1, byte_start-1)
    end
    cursor_pos = cursor_pos-1
    end
    end
    end
    elseif chord == 'left' then
    if cursor_pos > 1 then
    cursor_pos = cursor_pos - 1
    end
    elseif chord == 'right' then
    if cursor_pos <= #lines[cursor_line] then
    cursor_pos = cursor_pos + 1
    end
    elseif chord == 'delete' then
    if cursor_pos <= #lines[cursor_line] then
    local byte_start = utf8.offset(lines[cursor_line], cursor_pos)
    local byte_end = utf8.offset(lines[cursor_line], cursor_pos+1)
    if byte_start then
    if byte_end then
    lines[cursor_line] = string.sub(lines[cursor_line], 1, byte_start-1)..string.sub(lines[cursor_line], byte_end)
    else
    lines[cursor_line] = string.sub(lines[cursor_line], 1, byte_start-1)
    end
    -- no change to cursor_pos