1
This commit is contained in:
Alex Yatskov 2025-01-19 22:40:52 -08:00
parent c489fd3202
commit e57ee2ac20

View File

@ -51,26 +51,37 @@ function Cursor:is_string()
return name:find('String$') ~= nil return name:find('String$') ~= nil
end end
function Cursor:get_previous() function Cursor:get_previous(allow_line_break)
if self > Cursor.get_first() then if self > Cursor.get_first() then
local previous_cursor = Cursor.new(self.row, self.col - 1) local previous_cursor = Cursor.new(self.row, self.col - 1)
if previous_cursor.col < 1 then if previous_cursor.col < 1 then
previous_cursor.row = previous_cursor.row - 1 previous_cursor.row = previous_cursor.row - 1
local line = vim.fn.getline(previous_cursor.row ) local line = vim.fn.getline(previous_cursor.row )
previous_cursor.col = #line
local max_length = #line
if allow_line_break then
max_length = max_length + 1
end
previous_cursor.col = max_length
end end
return previous_cursor return previous_cursor
end end
end end
function Cursor:get_next() function Cursor:get_next(allow_line_break)
if self < Cursor.get_last() then if self < Cursor.get_last() then
local line = vim.fn.getline(self.row) local line = vim.fn.getline(self.row)
local next_cursor = Cursor.new(self.row, self.col + 1) local next_cursor = Cursor.new(self.row, self.col + 1)
if next_cursor.col > #line then local max_length = #line
if allow_line_break then
max_length = max_length + 1
end
if next_cursor.col > max_length then
next_cursor.row = next_cursor.row + 1 next_cursor.row = next_cursor.row + 1
next_cursor.col = 1 next_cursor.col = 1
end end