about summary refs log tree commit diff stats
path: root/source_text.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-04-08 22:21:55 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-04-08 22:28:19 -0700
commit6a7c5824c395b9bf48592f758f44186055f920b5 (patch)
tree4582c8f1b395523b335be271be2058900fd9e783 /source_text.lua
parentc969fcdd8574b42fd48e0695ea556a643aedb7c1 (diff)
downloadlines.love-6a7c5824c395b9bf48592f758f44186055f920b5.tar.gz
bugfix: syntax highlighting in source editor
I missed that comments only get highlighted at start of line.

This seems a bit hacky. But it continues to trade off CPU for reduced
memory footprint.
Diffstat (limited to 'source_text.lua')
-rw-r--r--source_text.lua9
1 files changed, 7 insertions, 2 deletions
diff --git a/source_text.lua b/source_text.lua
index d0b4fcc..cf3d00f 100644
--- a/source_text.lua
+++ b/source_text.lua
@@ -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 f: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