diff --git a/main.lua b/main.lua index 5c1abd9..19f9b21 100644 --- a/main.lua +++ b/main.lua @@ -116,10 +116,7 @@ function love.draw() end end}) if line_index == Cursor_line then - -- cursor - love.graphics.setColor(1,0,0) - love.graphics.circle('fill', 25,y+math.floor(15*Zoom), 2) - love.graphics.setColor(0,0,0) + Text.draw_cursor(25, y) end y = y + math.floor(15*Zoom) -- text height elseif line.mode == 'drawing' then diff --git a/text.lua b/text.lua index eac4818..44abc67 100644 --- a/text.lua +++ b/text.lua @@ -32,20 +32,14 @@ function Text.draw(line, line_width, line_index, cursor_line, cursor_pos) local frag_len = utf8.len(frag) if line_index == cursor_line then if pos <= cursor_pos and pos + frag_len > cursor_pos then - -- cursor - love.graphics.setColor(1,0,0) - love.graphics.circle('fill', x+Text.cursor_x2(frag, cursor_pos-pos+1),y+math.floor(15*Zoom), 2) - love.graphics.setColor(0,0,0) + Text.draw_cursor(x+Text.cursor_x2(frag, cursor_pos-pos+1), y) end end x = x + frag_width pos = pos + frag_len end if cursor_pos == pos then - -- cursor - love.graphics.setColor(1,0,0) - love.graphics.circle('fill', x,y+math.floor(15*Zoom), 2) - love.graphics.setColor(0,0,0) + Text.draw_cursor(x, y) end return y end @@ -54,6 +48,12 @@ end -- short words break on spaces -- long words break when they must +function Text.draw_cursor(x, y) + love.graphics.setColor(1,0,0) + love.graphics.circle('fill', x,y+math.floor(15*Zoom), 2) + love.graphics.setColor(0,0,0) +end + function Text.compute_fragments(line, line_width) line.fragments = {} local x = 25