From 8d1233a1440cb93f64ff1d6181138437251e3e63 Mon Sep 17 00:00:00 2001 From: Yi Ming Date: Tue, 19 May 2026 16:32:12 +0800 Subject: 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()`, --- runtime/lua/vim/range.lua | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) (limited to 'runtime/lua/vim/range.lua') 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(_, ...) -- cgit