diff --git a/lua/argonaut/param.lua b/lua/argonaut/param.lua index 3522370..5369315 100644 --- a/lua/argonaut/param.lua +++ b/lua/argonaut/param.lua @@ -14,7 +14,7 @@ function ParamCursorCell:hit_test(cursor) if self.cursor == cursor then return {{ type = 'cursor_cell', - value = self.cursor:get_value(), + char = self.cursor:get_value(), }} end end @@ -111,9 +111,9 @@ function Param:hit_test(cursor) local trace = cell:hit_test(cursor) if trace then table.insert(trace, 1, { - index = i, - length = #self.cells, - type = 'param_cell', + type = 'param', + cell_count = #self.cells, + cell_index = i, }) return trace @@ -123,11 +123,11 @@ end function Param:hit_search(trace, depth) local frame = trace[depth] - assert(frame.index <= #self.cells) - assert(frame.length == #self.cells) - assert(frame.type == 'param_cell') + assert(frame.type == 'param') + assert(frame.cell_count == #self.cells) + assert(frame.cell_index <= #self.cells) - return self.cells[frame.index]:hit_search(trace, depth + 1) + return self.cells[frame.cell_index]:hit_search(trace, depth + 1) end function Param:write(builder, wrapped) diff --git a/lua/argonaut/range.lua b/lua/argonaut/range.lua index 19fa87e..4d3aec0 100644 --- a/lua/argonaut/range.lua +++ b/lua/argonaut/range.lua @@ -105,40 +105,37 @@ end function Range:hit_test(cursor) if self:contains(cursor) then + local frame = { + type = 'range', + pairing = self.pairing.open .. self.pairing.close, + param_count = #self.params, + param_index = 0, + } + for i, param in pairs(self.params) do local trace = param:hit_test(cursor) if trace then - table.insert(trace, 1, { - index = i, - length = #self.params, - type = 'range_param', - value = self.pairing.open, - }) - + frame.param_index = i + table.insert(trace, 1, frame) return trace end end - return { - index = 0, - length = #self.params, - type = 'range_padding', - value = self.pairing.open, - } + return {frame} end end function Range:hit_search(trace, depth) local frame = trace[depth] - assert(frame.index <= #self.params) - assert(frame.length == #self.params) - assert(frame.type == 'range_param') - assert(frame.value == self.pairing.open) + assert(frame.type == 'range') + assert(frame.pairing == self.pairing.open .. self.pairing.close) + assert(frame.param_count == #self.params) + assert(frame.param_index <= #self.params) - if frame.index == 0 then + if frame.param_index == 0 then return self.start_cursor else - return self.params[frame.index]:hit_search(trace, depth + 1) + return self.params[frame.param_index]:hit_search(trace, depth + 1) end end