aboutsummaryrefslogtreecommitdiff
path: root/plugins/indentguide.lua
diff options
context:
space:
mode:
authorrxi <rxi@users.noreply.github.com>2020-04-23 20:49:37 +0100
committerrxi <rxi@users.noreply.github.com>2020-04-23 20:49:37 +0100
commit676f04945010aeb2ae71325bf2d1d6f336a5e162 (patch)
tree31b2e18df5e84fbc731840e5f1b28c974eea868a /plugins/indentguide.lua
parent9049e189d49440939192874d54af15a21eebbafb (diff)
downloadlite-xl-plugins-676f04945010aeb2ae71325bf2d1d6f336a5e162.tar.gz
lite-xl-plugins-676f04945010aeb2ae71325bf2d1d6f336a5e162.zip
Moved all plugins to `plugins` dir
Diffstat (limited to 'plugins/indentguide.lua')
-rw-r--r--plugins/indentguide.lua40
1 files changed, 40 insertions, 0 deletions
diff --git a/plugins/indentguide.lua b/plugins/indentguide.lua
new file mode 100644
index 0000000..9d903b7
--- /dev/null
+++ b/plugins/indentguide.lua
@@ -0,0 +1,40 @@
+local style = require "core.style"
+local config = require "core.config"
+local DocView = require "core.docview"
+
+
+local function get_line_spaces(doc, idx, dir)
+ local text = doc.lines[idx]
+ if not text then
+ return 0
+ end
+ local s, e = text:find("^%s*")
+ if e == #text then
+ return get_line_spaces(doc, idx + dir, dir)
+ end
+ return e - s + 1
+end
+
+
+local function get_line_indent_guide_spaces(doc, idx)
+ if doc.lines[idx]:find("^%s*\n") then
+ return math.max(
+ get_line_spaces(doc, idx - 1, -1),
+ get_line_spaces(doc, idx + 1, 1))
+ end
+ return get_line_spaces(doc, idx)
+end
+
+
+local draw_line_text = DocView.draw_line_text
+
+function DocView:draw_line_text(idx, x, y)
+ local spaces = get_line_indent_guide_spaces(self.doc, idx)
+ local sw = self:get_font():get_width(" ")
+ local h = self:get_line_height()
+ for i = 0, spaces - 1, config.indent_size do
+ local color = style.guide or style.selection
+ renderer.draw_rect(x + sw * i, y, style.divider_size, h, color)
+ end
+ draw_line_text(self, idx, x, y)
+end