From fdc04ae0c45c48a900eedc8aa08d0021232b3c0a Mon Sep 17 00:00:00 2001 From: Guldoman Date: Tue, 9 Nov 2021 21:26:14 +0100 Subject: Add `extend_selection_line` --- plugins/extend_selection_line.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 plugins/extend_selection_line.lua (limited to 'plugins/extend_selection_line.lua') diff --git a/plugins/extend_selection_line.lua b/plugins/extend_selection_line.lua new file mode 100644 index 0000000..a780fe0 --- /dev/null +++ b/plugins/extend_selection_line.lua @@ -0,0 +1,19 @@ +-- mod-version:2 -- lite-xl 2.0 +local DocView = require "core.docview" +local style = require "core.style" + +local draw_line_body = DocView.draw_line_body +function DocView:draw_line_body(idx, x, y, ...) + local lh = self:get_line_height() + for _, line1, _, line2, _ in self.doc:get_selections(true) do + if idx >= line1 and idx < line2 and line1 ~= line2 then + -- draw selection from the end of the line to the end of the available space + local x1 = x + self:get_col_x_offset(idx, #self.doc.lines[idx]) + local x2 = x + self.scroll.x + self.size.x + if x2 > x1 then + renderer.draw_rect(x1, y, x2 - x1, lh, style.selection) + end + end + end + draw_line_body(self, idx, x, y, ...) +end -- cgit v1.2.3 From dc64ff09521cf98a9adc44be8c5a019d62e7aa17 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Tue, 9 Nov 2021 21:46:13 +0100 Subject: `extend_selection_line`: Draw line body before drawing extension This avoids problems such as drawing the line highlight over the extension. This will probably conflict with other plugins that write after the end of the line. --- plugins/extend_selection_line.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/extend_selection_line.lua') diff --git a/plugins/extend_selection_line.lua b/plugins/extend_selection_line.lua index a780fe0..e986597 100644 --- a/plugins/extend_selection_line.lua +++ b/plugins/extend_selection_line.lua @@ -4,6 +4,7 @@ local style = require "core.style" local draw_line_body = DocView.draw_line_body function DocView:draw_line_body(idx, x, y, ...) + draw_line_body(self, idx, x, y, ...) local lh = self:get_line_height() for _, line1, _, line2, _ in self.doc:get_selections(true) do if idx >= line1 and idx < line2 and line1 ~= line2 then @@ -15,5 +16,4 @@ function DocView:draw_line_body(idx, x, y, ...) end end end - draw_line_body(self, idx, x, y, ...) end -- cgit v1.2.3