aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/highlight.lua
diff options
context:
space:
mode:
authorNAKAI Tsuyoshi <82267684+uga-rosa@users.noreply.github.com>2023-04-11 23:28:46 +0900
committerGitHub <noreply@github.com>2023-04-11 16:28:46 +0200
commit9e86f473e0f4e21c5f40bf990c53194d593a0f9f (patch)
tree39f52084142ee87eb1e23a0aaa04eb337bca8f93 /runtime/lua/vim/highlight.lua
parentaab95ec67e4d80e63cc5c5acc42f3832e76e0781 (diff)
downloadrneovim-9e86f473e0f4e21c5f40bf990c53194d593a0f9f.tar.gz
rneovim-9e86f473e0f4e21c5f40bf990c53194d593a0f9f.tar.bz2
rneovim-9e86f473e0f4e21c5f40bf990c53194d593a0f9f.zip
feat(lua): vim.region accepts getpos() arg (#22635)
Diffstat (limited to 'runtime/lua/vim/highlight.lua')
-rw-r--r--runtime/lua/vim/highlight.lua19
1 files changed, 4 insertions, 15 deletions
diff --git a/runtime/lua/vim/highlight.lua b/runtime/lua/vim/highlight.lua
index d71a806ea8..a6cfcb730f 100644
--- a/runtime/lua/vim/highlight.lua
+++ b/runtime/lua/vim/highlight.lua
@@ -15,8 +15,8 @@ M.priorities = {
---@param bufnr integer Buffer number to apply highlighting to
---@param ns integer Namespace to add highlight to
---@param higroup string Highlight group to use for highlighting
----@param start { [1]: integer, [2]: integer } Start position {line, col}
----@param finish { [1]: integer, [2]: integer } Finish position {line, col}
+---@param start integer[]|string Start of region as a (line, column) tuple or string accepted by |getpos()|
+---@param finish integer[]|string End of region as a (line, column) tuple or string accepted by |getpos()|
---@param opts table|nil Optional parameters
-- - regtype type of range (see |setreg()|, default charwise)
-- - inclusive boolean indicating whether the range is end-inclusive (default false)
@@ -27,11 +27,6 @@ function M.range(bufnr, ns, higroup, start, finish, opts)
local inclusive = opts.inclusive or false
local priority = opts.priority or M.priorities.user
- -- sanity check
- if start[2] < 0 or finish[1] < start[1] then
- return
- end
-
local region = vim.region(bufnr, start, finish, regtype, inclusive)
for linenr, cols in pairs(region) do
local end_row
@@ -104,18 +99,12 @@ function M.on_yank(opts)
yank_timer:close()
end
- local pos1 = vim.fn.getpos("'[")
- local pos2 = vim.fn.getpos("']")
-
- pos1 = { pos1[2] - 1, pos1[3] - 1 + pos1[4] }
- pos2 = { pos2[2] - 1, pos2[3] - 1 + pos2[4] }
-
M.range(
bufnr,
yank_ns,
higroup,
- pos1,
- pos2,
+ "'[",
+ "']",
{ regtype = event.regtype, inclusive = event.inclusive, priority = M.priorities.user }
)