~mcepl/vis-yank-highlight

f1f1ef2cb483f61c12e9627b8f85ae31d496fc1c — Randy Palamar 7 months ago 3ec213b
make style and duration configurable

the style definition is the same as a normal vis theme definition.
1 files changed, 10 insertions(+), 3 deletions(-)

M init.lua
M init.lua => init.lua +10 -3
@@ 1,15 1,22 @@
require("vis")

local M = {
	style = "reverse", -- Style used for highlighting
	duration = 0.5,    -- [s] Time to remain highlighted (10 ms precision)
}

vis.events.subscribe(vis.events.INIT, function()
	local yank = vis:action_register("highlighted-yank", function()
		vis.win:style_define(vis.win.STYLE_SELECTION, "reverse")
		vis.win:style_define(vis.win.STYLE_SELECTION, M.style)
		vis:redraw()
		local tstamp = os.clock()
		while os.clock() - tstamp < 0.5 do end
		while os.clock() - tstamp < M.duration do end
		vis.win:style_define(vis.win.STYLE_SELECTION, vis.lexers.STYLE_SELECTION)
		vis:redraw()
	end, "Yank operator with highlighting")
	vis:map(vis.modes.OPERATOR_PENDING, "y", yank)
	vis:map(vis.modes.VISUAL, "y", yank)
	vis:map(vis.modes.VISUAL_LINE, "y", yank)
end)
\ No newline at end of file
end)

return M