aboutsummaryrefslogtreecommitdiff
path: root/plugins/motiontrail.lua
diff options
context:
space:
mode:
authorrxi <rxi@users.noreply.github.com>2020-05-29 12:52:20 +0100
committerrxi <rxi@users.noreply.github.com>2020-05-29 12:52:20 +0100
commit7a47b97e21983913b98267484b4fd2a38cef3efa (patch)
treee76459a36e0ede1d5424cf369a791a6ca3aee930 /plugins/motiontrail.lua
parentb80e49cb2c606f434b77ef2a0cd1f0a85db42f52 (diff)
downloadlite-xl-plugins-7a47b97e21983913b98267484b4fd2a38cef3efa.tar.gz
lite-xl-plugins-7a47b97e21983913b98267484b4fd2a38cef3efa.zip
Added `motiontrail` plugin
Diffstat (limited to 'plugins/motiontrail.lua')
-rw-r--r--plugins/motiontrail.lua46
1 files changed, 46 insertions, 0 deletions
diff --git a/plugins/motiontrail.lua b/plugins/motiontrail.lua
new file mode 100644
index 0000000..e688e1b
--- /dev/null
+++ b/plugins/motiontrail.lua
@@ -0,0 +1,46 @@
+local core = require "core"
+local config = require "core.config"
+local style = require "core.style"
+local DocView = require "core.docview"
+
+config.motiontrail_steps = 50
+
+
+local function lerp(a, b, t)
+ return a + (b - a) * t
+end
+
+
+local function get_caret_rect(dv)
+ local line, col = dv.doc:get_selection()
+ local x, y = dv:get_line_screen_position(line)
+ x = x + dv:get_col_x_offset(line, col)
+ return x, y, style.caret_width, dv:get_line_height()
+end
+
+
+local last_x, last_y, last_view
+
+local draw = DocView.draw
+
+function DocView:draw(...)
+ draw(self, ...)
+ if self ~= core.active_view then return end
+
+ local x, y, w, h = get_caret_rect(self)
+
+ if last_view == self and (x ~= last_x or y ~= last_y) then
+ local lx = x
+ for i = 0, 1, 1 / config.motiontrail_steps do
+ local ix = lerp(x, last_x, i)
+ local iy = lerp(y, last_y, i)
+ local iw = math.max(w, math.ceil(math.abs(ix - lx)))
+ renderer.draw_rect(ix, iy, iw, h, style.caret)
+ lx = ix
+ end
+ core.redraw = true
+ end
+
+ last_view, last_x, last_y = self, x, y
+end
+