Draw only visible whitespaces

This commit is contained in:
Guldoman 2021-11-17 02:57:14 +01:00
parent 0525e6e96a
commit 6a7a02542f
No known key found for this signature in database
GPG Key ID: C08A498EC7F1AFDD
1 changed files with 8 additions and 4 deletions

View File

@ -9,24 +9,28 @@ local draw_line_text = DocView.draw_line_text
function DocView:draw_line_text(idx, x, y) function DocView:draw_line_text(idx, x, y)
local font = (self:get_font() or style.syntax_fonts["comment"]) local font = (self:get_font() or style.syntax_fonts["comment"])
local color = style.syntax.comment local color = style.syntax.comment
local ty, tx = y + self:get_line_text_y_offset() local ty = y + self:get_line_text_y_offset()
local tx
local text, offset, s, e = self.doc.lines[idx], 1 local text, offset, s, e = self.doc.lines[idx], 1
local x1, _, x2, _ = self:get_content_bounds()
local _offset = self:get_x_offset_col(idx, x1)
offset = _offset
while true do while true do
s, e = text:find(" +", offset) s, e = text:find(" +", offset)
if not s then break end if not s then break end
tx = self:get_col_x_offset(idx, s) + x tx = self:get_col_x_offset(idx, s) + x
renderer.draw_text(font, string.rep("·", e - s + 1), tx, ty, color) renderer.draw_text(font, string.rep("·", e - s + 1), tx, ty, color)
if tx > x + x2 then break end
offset = e + 1 offset = e + 1
end end
offset = 1 offset = _offset
while true do while true do
s, e = text:find("\t", offset) s, e = text:find("\t", offset)
if not s then break end if not s then break end
tx = self:get_col_x_offset(idx, s) + x tx = self:get_col_x_offset(idx, s) + x
renderer.draw_text(font, "»", tx, ty, color) renderer.draw_text(font, "»", tx, ty, color)
if tx > x + x2 then break end
offset = e + 1 offset = e + 1
end end
draw_line_text(self, idx, x, y) draw_line_text(self, idx, x, y)
end end