move
[?]
May 20, 2022, 5:58 AM
PFT5Y2ZYGQA6XXOZ5HH75WVUGA4B3KTDRHSFOZRAUKTPSFOPMNRACDependencies
- [2]
H2DPLWMVsnapshot: wrapping long lines at word boundaries - [3]
BULPIBEGbeginnings of a module for the text editor - [4]
XNFTJHC4split keyboard handling between Text and Drawing - [5]
B3IWYWSRdelete another arg that can be deduced - [6]
BOFNXP5Gclicking now moves the cursor even on long, wrapped lines - [7]
DAENUOGVeliminate assumptions that line length == size in bytes
Change contents
- edit in text.lua at line 5
function Text.compute_fragments(line, line_width)line.fragments = {}local x = 25-- try to wrap at word boundariesfor frag in line.data:gmatch('%S*%s*') dolocal 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 thenwhile x + frag_width > line_width doif 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)endx = 25 -- new lineendendif #frag > 0 then--? print('inserting '..frag..' of width '..tostring(frag_width)..'px')table.insert(line.fragments, {data=frag, text=frag_text})endendend - edit in text.lua at line 57
function Text.compute_fragments(line, line_width)line.fragments = {}local x = 25-- try to wrap at word boundariesfor frag in line.data:gmatch('%S*%s*') dolocal 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 thenwhile x + frag_width > line_width doif 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)endx = 25 -- new lineendendif #frag > 0 then--? print('inserting '..frag..' of width '..tostring(frag_width)..'px')table.insert(line.fragments, {data=frag, text=frag_text})endendend