about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-04-08 22:57:01 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-04-08 22:57:01 -0700
commitb3a3321cd641975c0d0c438748a836d32a02d401 (patch)
tree94f4ae66f4f2668f119b2f261689841ddfabc05b
parent7e242db5236249be44b5d82838f184083fc44044 (diff)
parent25e7eb99a9f0d23dc2948812ba5f61da95d73948 (diff)
downloadtext.love-b3a3321cd641975c0d0c438748a836d32a02d401.tar.gz
Merge lines.love
-rw-r--r--source_text.lua19
-rw-r--r--text.lua11
2 files changed, 17 insertions, 13 deletions
diff --git a/source_text.lua b/source_text.lua
index d0b4fcc..178e0c4 100644
--- a/source_text.lua
+++ b/source_text.lua
@@ -18,12 +18,12 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
     local pos = line_cache.screen_line_starting_pos[i]
     if pos < startpos then
       -- render nothing
---?       print('skipping', f)
+--?       print('skipping', screen_line)
     else
       final_screen_line_starting_pos = pos
-      local f = Text.screen_line(line, line_cache, i)
---?       print('text.draw:', f, 'at', line_index,pos, 'after', x,y)
-      local frag_len = utf8.len(f)
+      local screen_line = Text.screen_line(line, line_cache, i)
+--?       print('text.draw:', screen_line, 'at', line_index,pos, 'after', x,y)
+      local frag_len = utf8.len(screen_line)
       -- render any link decorations
       for _,link_offsets in ipairs(line_cache.link_offsets) do
         local s,e,filename = unpack(link_offsets)
@@ -44,8 +44,13 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
         local lo, hi = Text.clip_selection(State, line_index, pos, pos+frag_len)
         Text.draw_highlight(State, line, State.left,y, pos, lo,hi)
       end
-      select_color(f)
-      App.screen.print(f, State.left,y)
+      -- render colorized text
+      local x = State.left
+      for frag in screen_line:gmatch('%S*%s*') do
+        select_color(frag)
+        App.screen.print(frag, x,y)
+        x = x+App.width(frag)
+      end
       -- render cursor if necessary
       if not hide_cursor and line_index == State.cursor1.line then
         if pos <= State.cursor1.pos and pos + frag_len >= State.cursor1.pos then
@@ -56,7 +61,7 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
               love.graphics.print(State.search_term, State.left+lo_px,y)
             end
           elseif Focus == 'edit' then
-            Text.draw_cursor(State, State.left+Text.x(f, State.cursor1.pos-pos+1), y)
+            Text.draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y)
           end
         end
       end
diff --git a/text.lua b/text.lua
index bee05a9..9abc6fe 100644
--- a/text.lua
+++ b/text.lua
@@ -17,19 +17,18 @@ function Text.draw(State, line_index, y, startpos)
     local pos = line_cache.screen_line_starting_pos[i]
     if pos < startpos then
       -- render nothing
---?       print('skipping', f)
     else
       final_screen_line_starting_pos = pos
-      local f = Text.screen_line(line, line_cache, i)
---?       print('text.draw:', f, 'at', line_index,pos, 'after', x,y)
-      local frag_len = utf8.len(f)
+      local screen_line = Text.screen_line(line, line_cache, i)
+--?       print('text.draw:', screen_line, 'at', line_index,pos, 'after', x,y)
+      local frag_len = utf8.len(screen_line)
       -- render fragment
       if State.selection1.line then
         local lo, hi = Text.clip_selection(State, line_index, pos, pos+frag_len)
         Text.draw_highlight(State, line, State.left,y, pos, lo,hi)
       end
       App.color(Text_color)
-      App.screen.print(f, State.left,y)
+      App.screen.print(screen_line, State.left,y)
       -- render cursor if necessary
       if line_index == State.cursor1.line then
         if pos <= State.cursor1.pos and pos + frag_len >= State.cursor1.pos then
@@ -40,7 +39,7 @@ function Text.draw(State, line_index, y, startpos)
               love.graphics.print(State.search_term, State.left+lo_px,y)
             end
           else
-            Text.draw_cursor(State, State.left+Text.x(f, State.cursor1.pos-pos+1), y)
+            Text.draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y)
           end
         end
       end