honeylisp/vendor/lite-plugins/plugins/motiontrail.lua
Jeremy Penner cb5132f393 git subrepo clone https://github.com/rxi/lite-plugins vendor/lite-plugins
subrepo:
  subdir:   "vendor/lite-plugins"
  merged:   "de4227d"
upstream:
  origin:   "https://github.com/rxi/lite-plugins"
  branch:   "master"
  commit:   "de4227d"
git-subrepo:
  version:  "0.4.2"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "65fde50"
2020-11-19 21:04:39 -05:00

47 lines
1 KiB
Lua

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