diff options
author | takase1121 <20792268+takase1121@users.noreply.github.com> | 2021-10-27 13:38:10 +0800 |
---|---|---|
committer | takase1121 <20792268+takase1121@users.noreply.github.com> | 2021-10-27 13:38:10 +0800 |
commit | a6e752d1eba6217d8a2f4cac3d170db39e37d713 (patch) | |
tree | 87ed200c859fa038aa972adbd443ff451597b8d8 | |
parent | 911d14ed38a5f96ec2175d4adbc1f8290fd61a32 (diff) | |
download | lite-xl-plugins-a6e752d1eba6217d8a2f4cac3d170db39e37d713.tar.gz lite-xl-plugins-a6e752d1eba6217d8a2f4cac3d170db39e37d713.zip |
add smoothcaret.lua
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | plugins/smoothcaret.lua | 26 |
2 files changed, 27 insertions, 0 deletions
@@ -126,6 +126,7 @@ Plugin | Description [`scalestatus`](plugins/scalestatus.lua?raw=1) | Displays current scale (zoom) in status view (depends on scale plugin) [`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))* [`smallclock`](plugins/smallclock.lua?raw=1) | Displays the current time in the corner of the status view +*[`smoothcaret`](plugins/smoothcaret.lua?raw=1)* | Smooth caret animation *([gif](https://user-images.githubusercontent.com/20792268/139006049-a0ba6559-88cb-49a7-8077-4822445b4a1f.gif))* [`sort`](plugins/sort.lua?raw=1) | Sorts selected lines alphabetically [`spellcheck`](plugins/spellcheck.lua?raw=1) | Underlines misspelt words *([screenshot](https://user-images.githubusercontent.com/3920290/79923973-9caa7400-842e-11ea-85d4-7a196a91ca50.png))* *— note: on Windows a [`words.txt`](https://github.com/dwyl/english-words/blob/master/words.txt) dictionary file must be placed beside the exe* [`tabnumbers`](plugins/tabnumbers.lua?raw=1) | Displays tab numbers from 1–9 next to their names *([screenshot](https://user-images.githubusercontent.com/16415678/101285362-007a8500-37e5-11eb-869b-c10eb9d9d902.png)) diff --git a/plugins/smoothcaret.lua b/plugins/smoothcaret.lua new file mode 100644 index 0000000..26f7d98 --- /dev/null +++ b/plugins/smoothcaret.lua @@ -0,0 +1,26 @@ +-- mod-version:2 -- lite-xl 2.0 +local config = require "core.config" +local style = require "core.style" +local DocView = require "core.docview" + +config.plugins.smoothcaret = { rate = 0.65 } + +local docview_update = DocView.update +function DocView:update() + docview_update(self) + + if not self.caret then + self.caret = { current = { x = 0, y = 0 }, target = { x = 0, y = 0 } } + end + local c = self.caret + self:move_towards(c.current, "x", c.target.x, config.plugins.smoothcaret.rate) + self:move_towards(c.current, "y", c.target.y, config.plugins.smoothcaret.rate) +end + +function DocView:draw_caret(x, y) + local c = self.caret + local lh = self:get_line_height() + c.target.x = x + c.target.y = y + renderer.draw_rect(c.current.x, c.current.y, style.caret_width, lh, style.caret) +end |