diff --git a/lua/argonaut/types.lua b/lua/argonaut/types.lua index 8c5de15..a915bcd 100644 --- a/lua/argonaut/types.lua +++ b/lua/argonaut/types.lua @@ -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