aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/range.lua
diff options
context:
space:
mode:
authorYi Ming <ofseed@foxmail.com>2026-05-19 16:32:12 +0800
committerYi Ming <ofseed@foxmail.com>2026-05-20 16:23:01 +0800
commit8d1233a1440cb93f64ff1d6181138437251e3e63 (patch)
treeeb5ad435af0288fbb5da48f83deb6143086a7518 /runtime/lua/vim/range.lua
parentf3bb21e71da09a357c0b05e53b4e11afdceb6621 (diff)
downloadrneovim-8d1233a1440cb93f64ff1d6181138437251e3e63.tar.gz
rneovim-8d1233a1440cb93f64ff1d6181138437251e3e63.tar.bz2
rneovim-8d1233a1440cb93f64ff1d6181138437251e3e63.zip
feat(pos,range)!: remove `range.cursor()` and `range:to_cursor()`,
Problem: - A window can only have one cursor, ranges selected by the cursor are typically obtained by marks like ">" and "<", instead of calling get_cursor() twice. - `vim.Range` is described as end-exclusive, but the current `range.cursor()`/`range:to_cursor()` are end-inclusive. - Conversion between `vim.Range` and mark-indexed range can be done by `range.mark()`/`range:to_mark()` Solution: Remove `range.cursor()` and `range:to_cursor()`,
Diffstat (limited to 'runtime/lua/vim/range.lua')
-rw-r--r--runtime/lua/vim/range.lua46
1 files changed, 0 insertions, 46 deletions
diff --git a/runtime/lua/vim/range.lua b/runtime/lua/vim/range.lua
index e069df4a3a..faf5f650ad 100644
--- a/runtime/lua/vim/range.lua
+++ b/runtime/lua/vim/range.lua
@@ -438,52 +438,6 @@ function M.extmark(buf, start_row, start_col, end_row, end_col)
return M.new(start, end_)
end
---- Converts |vim.Range| to mark-like range (see |api-indexing|).
----
---- Example:
---- ```lua
---- local range = vim.range(0, 3, 5, 4, 0)
----
---- -- Convert to cursor range, you can call it in a method style.
---- local cursor_range = range:to_cursor()
---- ```
----@param range vim.Range
-function M.to_cursor(range)
- validate('range', range, 'table')
-
- local srow, scol = vim.pos(range.buf, range[1], range[2]):to_cursor()
- local erow, ecol = vim.pos(range.buf, range[3], range[4]):to_cursor()
- return srow, scol, erow, ecol
-end
-
---- Creates a new |vim.Range| from mark-like range (see |api-indexing|).
----
---- Example:
---- ```lua
---- local start = vim.api.nvim_win_get_cursor(0)
---- -- move the cursor
---- local end_ = vim.api.nvim_win_get_cursor(0)
----
---- local range = vim.range.cursor(0, start, end_)
---- ```
----@param buf integer
----@param start_pos [integer, integer]
----@param end_pos [integer, integer]
-function M.cursor(buf, start_pos, end_pos)
- validate('buf', buf, 'number')
- validate('range', start_pos, 'table')
- validate('range', end_pos, 'table')
-
- if buf == 0 then
- buf = api.nvim_get_current_buf()
- end
-
- local start = vim.pos.cursor(buf, start_pos)
- local end_ = vim.pos.cursor(buf, end_pos)
-
- return M.new(start, end_)
-end
-
-- Overload `Range.new` to allow calling this module as a function.
setmetatable(M, {
__call = function(_, ...)