Still not working: clicking on text to move the cursor aborts up/down motions still move by logical lines rather than screen lines
H2DPLWMVRFYTO2CQTG54FMT2LF3B6UKLXH32CUA22DNQJVP5XBNQC 4C375P53EXHUPXUFQSI3LA7THEP2WOKX5ZB57OQ5ZSM7LYOVW5HAC BULPIBEGL7TMK6CVIE7IS7WGAHGOSUJBGJSFQK542MOWGHP2ADQQC B3IWYWSRDSZ7AG5HDS3TELNTG2IKRZYPI25B6LJGVFAJYTHVXZZAC XNFTJHC4QSHNSIWNN7K6QZEZ37GTQYKHS4EPNSVPQCUSWREROGIQC UWNHC4AAO3SPOYLPANTO4WKCTZL7KAYC73Q2YUZFFW7K26FVJ7FQC OTIBCAUJ3KDQJLVDN3A536DLZGNRYMGJLORZVR3WLCGXGO6UGO6AC DLQMM2656JHXX3ONOEM6UIOXKFJFT5QT7RHWK7YS2W77PVZWHRSAC function Text.draw(line, line_index, cursor_line, cursor_pos)
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})endendendfunction Text.draw(line, line_width, line_index, cursor_line, cursor_pos)love.graphics.setColor(0.75,0.75,0.75)love.graphics.line(line_width, 0, line_width, Screen_height)
local love_text = love.graphics.newText(love.graphics.getFont(), line.data)love.graphics.draw(love_text, 25,line.y, 0, Zoom)if line_index == cursor_line then-- cursorlove.graphics.print('_', Text.cursor_x(line.data, cursor_pos), line.y+6) -- drop the cursor down a bit to account for the increased font size
-- wrap long lineslocal x = 25local y = line.ylocal pos = 1if line.fragments == nil thenText.compute_fragments(line, line_width)endfor _, f in ipairs(line.fragments) dolocal frag, frag_text = f.data, f.text-- render fragmentlocal frag_width = math.floor(frag_text:getWidth()*Zoom)if x + frag_width > line_width thenassert(x > 25) -- no overfull linesy = y + math.floor(15*Zoom)x = 25endlove.graphics.draw(frag_text, x,y, 0, Zoom)-- render cursor if necessarylocal frag_len = utf8.len(frag)if line_index == cursor_line thenif pos <= cursor_pos and pos + frag_len > cursor_pos then-- cursorlove.graphics.print('_', x+Text.cursor_x2(frag, cursor_pos-pos+1), y+6) -- drop the cursor down a bit to account for the increased font sizeendendx = x + frag_widthpos = pos + frag_len