aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter/_range.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2026-05-20 05:35:09 -0400
committerGitHub <noreply@github.com>2026-05-20 05:35:09 -0400
commit1f75fef951562562985e40ff8fa9ccfc022214fd (patch)
tree057b5c3203e02eb9ccd57e720df32273c5848352 /runtime/lua/vim/treesitter/_range.lua
parentf1fad32e2ea4e5d06994d123603b565aa9c03a32 (diff)
parentcd3b544611aa2181b04c77ffd36f470a46c61879 (diff)
downloadrneovim-1f75fef951562562985e40ff8fa9ccfc022214fd.tar.gz
rneovim-1f75fef951562562985e40ff8fa9ccfc022214fd.tar.bz2
rneovim-1f75fef951562562985e40ff8fa9ccfc022214fd.zip
Merge #39889 from ofseed/pos-util
refactor(pos,range): drop `to_cursor`, extract `vim.pos._util`
Diffstat (limited to 'runtime/lua/vim/treesitter/_range.lua')
-rw-r--r--runtime/lua/vim/treesitter/_range.lua49
1 files changed, 3 insertions, 46 deletions
diff --git a/runtime/lua/vim/treesitter/_range.lua b/runtime/lua/vim/treesitter/_range.lua
index 8ec938acc5..b37135efc7 100644
--- a/runtime/lua/vim/treesitter/_range.lua
+++ b/runtime/lua/vim/treesitter/_range.lua
@@ -1,4 +1,5 @@
local api = vim.api
+local util = require('vim.pos._util')
local M = {}
@@ -25,52 +26,8 @@ local M = {}
---@alias Range Range2|Range4|Range6
----@param a_row integer
----@param a_col integer
----@param b_row integer
----@param b_col integer
----@return integer
---- 1: a > b
---- 0: a == b
---- -1: a < b
-local function cmp_pos(a_row, a_col, b_row, b_col)
- if a_row == b_row then
- if a_col > b_col then
- return 1
- elseif a_col < b_col then
- return -1
- else
- return 0
- end
- elseif a_row > b_row then
- return 1
- end
-
- return -1
-end
-
-M.cmp_pos = {
- lt = function(...)
- return cmp_pos(...) == -1
- end,
- le = function(...)
- return cmp_pos(...) ~= 1
- end,
- gt = function(...)
- return cmp_pos(...) == 1
- end,
- ge = function(...)
- return cmp_pos(...) ~= -1
- end,
- eq = function(...)
- return cmp_pos(...) == 0
- end,
- ne = function(...)
- return cmp_pos(...) ~= 0
- end,
-}
-
-setmetatable(M.cmp_pos, { __call = cmp_pos })
+-- TODO(ofseed): directly use `cmp_pos` from `util` and replace all exported usages.
+M.cmp_pos = util.cmp_pos
---Check if a variable is a valid range object
---@param r any