diff options
author | jgmdev <jgmdev@gmail.com> | 2022-10-15 21:43:40 -0400 |
---|---|---|
committer | jgmdev <jgmdev@gmail.com> | 2022-10-15 21:43:56 -0400 |
commit | ed427dd76806e2ec9a1ae7ccb1184e4b30cec16b (patch) | |
tree | 29f94997e547aa30974994e2d92cbb2882d52960 /plugins | |
parent | de6ddb686cd6caade7ff4304c6f7f4bd1f2416fd (diff) | |
download | lite-xl-plugins-ed427dd76806e2ec9a1ae7ccb1184e4b30cec16b.tar.gz lite-xl-plugins-ed427dd76806e2ec9a1ae7ccb1184e4b30cec16b.zip |
indentguide: do not apply on CommandView and allow toggling it.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/indentguide.lua | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/plugins/indentguide.lua b/plugins/indentguide.lua index 71c6269..42eb3a6 100644 --- a/plugins/indentguide.lua +++ b/plugins/indentguide.lua @@ -1,8 +1,23 @@ -- mod-version:3 local style = require "core.style" local config = require "core.config" +local common = require "core.common" local DocView = require "core.docview" +config.plugins.indentguide = common.merge({ + enabled = true, + -- The config specification used by the settings gui + config_spec = { + name = "Indent Guide", + { + label = "Enable", + description = "Toggle the drawing of indentation indicator lines.", + path = "enabled", + type = "toggle", + default = true + } + } +}, config.plugins.indentguide) -- TODO: replace with `doc:get_indent_info()` when 2.1 releases local function get_indent_info(doc) @@ -44,6 +59,10 @@ local docview_update = DocView.update function DocView:update() docview_update(self) + if not config.plugins.indentguide.enabled or not self:is(DocView) then + return + end + local function get_indent(line) if line < 1 or line > #self.doc.lines then return -1 end if not self.indentguide_indents[line] then @@ -104,20 +123,22 @@ end local draw_line_text = DocView.draw_line_text function DocView:draw_line_text(line, x, y) - local spaces = self.indentguide_indents[line] or -1 - local _, indent_size = get_indent_info(self.doc) - local w = math.max(1, SCALE) - local h = self:get_line_height() - local font = self:get_font() - local space_sz = font:get_width(" ") - for i = 0, spaces - 1, indent_size do - local color = style.guide or style.selection - local active_lvl = self.indentguide_indent_active[line] or -1 - if i < active_lvl and i + indent_size >= active_lvl then - color = style.guide_highlight or style.accent + if config.plugins.indentguide.enabled and self:is(DocView) then + local spaces = self.indentguide_indents[line] or -1 + local _, indent_size = get_indent_info(self.doc) + local w = math.max(1, SCALE) + local h = self:get_line_height() + local font = self:get_font() + local space_sz = font:get_width(" ") + for i = 0, spaces - 1, indent_size do + local color = style.guide or style.selection + local active_lvl = self.indentguide_indent_active[line] or -1 + if i < active_lvl and i + indent_size >= active_lvl then + color = style.guide_highlight or style.accent + end + local sw = space_sz * i + renderer.draw_rect(math.ceil(x + sw), y, w, h, color) end - local sw = space_sz * i - renderer.draw_rect(math.ceil(x + sw), y, w, h, color) end return draw_line_text(self, line, x, y) end |