about summary refs log tree commit diff stats
path: root/text.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-20 05:40:42 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-20 05:40:42 -0700
commit5f2ef2faafa19e095ec5d447d0e24f98c473d31a (patch)
tree7479c5254e951f3351d3abd63538f011a32411f5 /text.lua
parente223182ad55ca79f864c93641664ce85b389582b (diff)
downloadview.love-5f2ef2faafa19e095ec5d447d0e24f98c473d31a.tar.gz
extract a function
Diffstat (limited to 'text.lua')
-rw-r--r--text.lua16
1 files changed, 8 insertions, 8 deletions
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