1
This commit is contained in:
Alex Yatskov 2024-05-04 19:45:21 -07:00
parent 48d807a0a1
commit b0fea0257b

View File

@ -31,6 +31,33 @@ function Cursor:set_current()
vim.fn.setcursorcharpos({self.row, self.col})
end
function Cursor:forward()
assert(self:is_valid())
if self.col < #vim.fn.getline(self.row) then
self.col = self.col + 1
else
self.row = self.row + 1
self.col = 1
end
end
function Cursor:backward()
assert(self:is_valid())
if self.col > 1 then
self.col = self.col - 1
elseif self.row > 1 then
self.row = self.row - 1
self.col = #vim.fn.getline(self.row)
end
end
function Cursor:get_char()
assert(self:is_valid())
local line = vim.fn.getline(self.row)
assert(self.col <= #line)
return line:sub(self.col, self.col)
end
function Cursor.__eq(self, other)
return self.row == other.row and self.col == other.col
end
@ -385,9 +412,9 @@ function ParamList:parse()
end
function ParamList:get_active_param()
for _, param in ipairs(self.parsed) do
for i, param in ipairs(self.parsed) do
if param.offset then
return param
return i, param
end
end
end
@ -621,20 +648,25 @@ function WrapContext:toggle()
end
function WrapContext:object_i()
local param = self.params:get_active_param()
local _, param = self.params:get_active_param()
if param then
param.start:set_current()
vim.fn.searchpos('\\S', 'cW')
vim.cmd.normal('v')
param.stop:set_current()
vim.fn.searchpos('\\S', 'cbW')
end
end
function WrapContext:object_a()
local param = self.params:get_active_param()
local _, param = self.params:get_active_param()
if param then
param.start:set_current()
vim.fn.searchpos('\\S', 'cbW')
vim.fn.searchpos('[^\\<\\(\\{\\[]', 'cW')
vim.cmd.normal('v')
param.stop:set_current()
vim.fn.searchpos('\\S', 'cW')
end
end