diff options
author | Guldoman <giulio.lettieri@gmail.com> | 2022-04-24 23:58:46 +0200 |
---|---|---|
committer | Guldoman <giulio.lettieri@gmail.com> | 2022-04-24 23:58:46 +0200 |
commit | 25b576f6ee81b6913cc772e1d7465d3648f5a23e (patch) | |
tree | 342d2e5f00e9d09bc6b2db2d53519d56ca851fcc /plugins | |
parent | d663a04e56573c3db9ec58c77c82a2a7925aa1bb (diff) | |
download | lite-xl-plugins-25b576f6ee81b6913cc772e1d7465d3648f5a23e.tar.gz lite-xl-plugins-25b576f6ee81b6913cc772e1d7465d3648f5a23e.zip |
Add multicursor support to `indentguide`
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/indentguide.lua | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/plugins/indentguide.lua b/plugins/indentguide.lua index 1c4f8ae..c7e781c 100644 --- a/plugins/indentguide.lua +++ b/plugins/indentguide.lua @@ -60,39 +60,44 @@ function DocView:update() self.lineguide_indents[i] = get_line_indent_guide_spaces(self.doc, i) end - local line = self.doc:get_selection() - local lvl = get_indent(line) - local top, bottom local _, indent_size = get_indent_info(self.doc) - - -- check if we're the header or the footer of a block - if get_indent(line + 1) > lvl and get_indent(line + 1) <= lvl + indent_size then - top = true - lvl = get_indent(line + 1) - elseif get_indent(line - 1) > lvl and get_indent(line - 1) <= lvl + indent_size then - bottom = true - lvl = get_indent(line - 1) - end - - self.lineguide_indent_active[line] = lvl - - -- check if the lines before the current are part of the block - local i = line - 1 - if i > 0 and not top then - repeat - if get_indent(i) <= lvl - indent_size then break end - self.lineguide_indent_active[i] = lvl - i = i - 1 - until i < minline - end - -- check if the lines after the current are part of the block - i = line + 1 - if i <= #self.doc.lines and not bottom then - repeat - if get_indent(i) <= lvl - indent_size then break end - self.lineguide_indent_active[i] = lvl - i = i + 1 - until i > maxline + for _,line in self.doc:get_selections() do + local lvl = get_indent(line) + local top, bottom + + if not self.lineguide_indent_active[line] + or self.lineguide_indent_active[line] > lvl then + + -- check if we're the header or the footer of a block + if get_indent(line + 1) > lvl and get_indent(line + 1) <= lvl + indent_size then + top = true + lvl = get_indent(line + 1) + elseif get_indent(line - 1) > lvl and get_indent(line - 1) <= lvl + indent_size then + bottom = true + lvl = get_indent(line - 1) + end + + self.lineguide_indent_active[line] = lvl + + -- check if the lines before the current are part of the block + local i = line - 1 + if i > 0 and not top then + repeat + if get_indent(i) <= lvl - indent_size then break end + self.lineguide_indent_active[i] = lvl + i = i - 1 + until i < minline + end + -- check if the lines after the current are part of the block + i = line + 1 + if i <= #self.doc.lines and not bottom then + repeat + if get_indent(i) <= lvl - indent_size then break end + self.lineguide_indent_active[i] = lvl + i = i + 1 + until i > maxline + end + end end end |