aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuldoman <giulio.lettieri@gmail.com>2021-11-09 21:26:14 +0100
committerGuldoman <giulio.lettieri@gmail.com>2021-11-09 21:26:14 +0100
commitfdc04ae0c45c48a900eedc8aa08d0021232b3c0a (patch)
treefe3e39bd597e708cdd2159741120d361467bbb80
parent911d14ed38a5f96ec2175d4adbc1f8290fd61a32 (diff)
downloadlite-xl-plugins-fdc04ae0c45c48a900eedc8aa08d0021232b3c0a.tar.gz
lite-xl-plugins-fdc04ae0c45c48a900eedc8aa08d0021232b3c0a.zip
Add `extend_selection_line`
-rw-r--r--README.md1
-rw-r--r--plugins/extend_selection_line.lua19
2 files changed, 20 insertions, 0 deletions
diff --git a/README.md b/README.md
index 5e40895..a521c12 100644
--- a/README.md
+++ b/README.md
@@ -34,6 +34,7 @@ Plugin | Description
[`eval`](plugins/eval.lua?raw=1) | Replaces selected Lua code with its evaluated result
[`exec`](plugins/exec.lua?raw=1) | Runs selected text through shell command and replaces with result
[`ephemeraldocviews`](plugins/ephemeraldocviews.lua?raw=1) | Preview tabs. Opening a doc will replace the contents of the preview tab. Marks tabs as non-preview on any change.
+*[`extend_selection_line`](plugins/extend_selection_line.lua?raw=1)* | When a selection crosses multiple lines, it is drawn to the end of the screen *([screenshot](https://user-images.githubusercontent.com/2798487/140995616-89a20b55-5917-4df8-8a7c-d7c53732fa8b.png))*
[`fallbackfonts`](https://github.com/takase1121/lite-fallback-fonts)* | Adds support for fallback fonts *([gif](https://raw.githubusercontent.com/takase1121/lite-fallback-fonts/master/assets/Iw18fI57J0.gif))*
[`fontconfig`](plugins/fontconfig.lua?raw=1) | Allows users to load fonts with [fontconfig](https://www.freedesktop.org/software/fontconfig/fontconfig-user.html).
[`formatter`](https://github.com/vincens2005/lite-formatters)* | formatters for various languages
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