aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--plugins/motiontrail.lua46
2 files changed, 47 insertions, 0 deletions
diff --git a/README.md b/README.md
index a59b28d..ed9fffd 100644
--- a/README.md
+++ b/README.md
@@ -51,6 +51,7 @@ Plugin | Description
[`linter`](https://github.com/drmargarido/linters)* | Linters for multiple languages
[`macmodkeys`](plugins/macmodkeys.lua?raw=1) | Remaps mac modkeys `command/option` to `ctrl/alt`
[`markers`](plugins/markers.lua?raw=1) | Add markers to docs and jump between them quickly *([screenshot](https://user-images.githubusercontent.com/3920290/82252149-5faaa200-9946-11ea-9199-bea2efb7ee23.png))*
+[`motiontrail`](plugins/motiontrail.lua?raw=1) | Adds a motion-trail to the caret *([screenshot](https://user-images.githubusercontent.com/3920290/83256814-085ccb00-a1ab-11ea-9e35-e6633cbed1a9.gif))*
[`openfilelocation`](plugins/openfilelocation.lua?raw=1) | Opens the parent directory of the current file in the file manager
[`openselected`](plugins/openselected.lua?raw=1) | Opens the selected filename or url
[`selectionhighlight`](plugins/selectionhighlight.lua?raw=1) | Highlights regions of code that match the current selection *([screenshot](https://user-images.githubusercontent.com/3920290/80710883-5f597c80-8ae7-11ea-97f0-76dfacc08439.png))*
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
+