move

[?]
May 20, 2022, 5:58 AM
PFT5Y2ZYGQA6XXOZ5HH75WVUGA4B3KTDRHSFOZRAUKTPSFOPMNRAC

Dependencies

  • [2] H2DPLWMV snapshot: wrapping long lines at word boundaries
  • [3] BULPIBEG beginnings of a module for the text editor
  • [4] XNFTJHC4 split keyboard handling between Text and Drawing
  • [5] B3IWYWSR delete another arg that can be deduced
  • [6] BOFNXP5G clicking now moves the cursor even on long, wrapped lines
  • [7] DAENUOGV eliminate assumptions that line length == size in bytes

Change contents

  • edit in text.lua at line 5
    [3.30][3.43:44](),[3.43][3.43:44](),[3.44][2.1:1567]()
    function Text.compute_fragments(line, line_width)
    line.fragments = {}
    local x = 25
    -- try to wrap at word boundaries
    for frag in line.data:gmatch('%S*%s*') do
    local frag_text = love.graphics.newText(love.graphics.getFont(), frag)
    local frag_width = math.floor(frag_text:getWidth()*Zoom)
    --? print('x: '..tostring(x)..'; '..tostring(line_width-x)..'px to go')
    --? print('frag: ^'..frag..'$ is '..tostring(frag_width)..'px wide')
    if x + frag_width > line_width then
    while x + frag_width > line_width do
    if x < 0.8*line_width then
    -- long word; chop it at some letter
    -- We're not going to reimplement TeX here.
    local b = Text.nearest_cursor_pos(frag, line_width - x)
    --? print('space for '..tostring(b)..' graphemes')
    local frag1 = string.sub(frag, 1, b)
    local frag1_text = love.graphics.newText(love.graphics.getFont(), frag1)
    local frag1_width = math.floor(frag1_text:getWidth()*Zoom)
    --? print('inserting '..frag1..' of width '..tostring(frag1_width)..'px')
    table.insert(line.fragments, {data=frag1, text=frag1_text})
    frag = string.sub(frag, b+1)
    frag_text = love.graphics.newText(love.graphics.getFont(), frag)
    frag_width = math.floor(frag_text:getWidth()*Zoom)
    end
    x = 25 -- new line
    end
    end
    if #frag > 0 then
    --? print('inserting '..frag..' of width '..tostring(frag_width)..'px')
    table.insert(line.fragments, {data=frag, text=frag_text})
    end
    end
    end
  • edit in text.lua at line 57
    [3.42]
    [3.42]
    function Text.compute_fragments(line, line_width)
    line.fragments = {}
    local x = 25
    -- try to wrap at word boundaries
    for frag in line.data:gmatch('%S*%s*') do
    local frag_text = love.graphics.newText(love.graphics.getFont(), frag)
    local frag_width = math.floor(frag_text:getWidth()*Zoom)
    --? print('x: '..tostring(x)..'; '..tostring(line_width-x)..'px to go')
    --? print('frag: ^'..frag..'$ is '..tostring(frag_width)..'px wide')
    if x + frag_width > line_width then
    while x + frag_width > line_width do
    if x < 0.8*line_width then
    -- long word; chop it at some letter
    -- We're not going to reimplement TeX here.
    local b = Text.nearest_cursor_pos(frag, line_width - x)
    --? print('space for '..tostring(b)..' graphemes')
    local frag1 = string.sub(frag, 1, b)
    local frag1_text = love.graphics.newText(love.graphics.getFont(), frag1)
    local frag1_width = math.floor(frag1_text:getWidth()*Zoom)
    --? print('inserting '..frag1..' of width '..tostring(frag1_width)..'px')
    table.insert(line.fragments, {data=frag1, text=frag1_text})
    frag = string.sub(frag, b+1)
    frag_text = love.graphics.newText(love.graphics.getFont(), frag)
    frag_width = math.floor(frag_text:getWidth()*Zoom)
    end
    x = 25 -- new line
    end
    end
    if #frag > 0 then
    --? print('inserting '..frag..' of width '..tostring(frag_width)..'px')
    table.insert(line.fragments, {data=frag, text=frag_text})
    end
    end
    end