diff --git a/lua/argonaut/param.lua b/lua/argonaut/param.lua index a463dca..f2041c7 100644 --- a/lua/argonaut/param.lua +++ b/lua/argonaut/param.lua @@ -119,22 +119,35 @@ function Param:append(cell) table.insert(self.cells, cell) end +function Param:validate() + local index_begin = self:find_index_begin() + local index_end = self:find_index_end() + + for i = index_begin, index_end - 1 do + local cell = self.cells[i] + local next_cell = self.cells[i + 1] + if cell:get_stop_row() ~= next_cell:get_start_row() then + return false + end + end + + return true +end + function Param:hit_test(cursor) local index_begin = self:find_index_begin() local index_end = self:find_index_end() for i = 1, index_begin - 1, 1 do local cell = self.cells[i] - local trace = cell:hit_test(cursor) - if trace then + if cell:hit_test(cursor) then cursor = cursor:get_next() end end for i = #self.cells, index_end + 1, -1 do local cell = self.cells[i] - local trace = cell:hit_test(cursor) - if trace then + if cell:hit_test(cursor) then cursor = cursor:get_previous() end end diff --git a/lua/argonaut/range.lua b/lua/argonaut/range.lua index 5ae12bd..f685d69 100644 --- a/lua/argonaut/range.lua +++ b/lua/argonaut/range.lua @@ -28,9 +28,7 @@ local function find_closest() if #ranges > 0 then table.sort(ranges) - local range = ranges[1] - range:parse() - return range + return ranges[1] end end @@ -51,9 +49,7 @@ local function find_at_cursor(start_cursor, parent_range) return end - local range = Range.new(start_cursor, stop_cursor, pairing) - range:parse() - return range + return Range.new(start_cursor, stop_cursor, pairing) end end @@ -65,7 +61,11 @@ function Range.new(start_cursor, stop_cursor, pairing) params = {}, } - return setmetatable(range, Range) + setmetatable(range, Range) + + if range:parse() then + return range + end end function Range:parse() @@ -109,6 +109,17 @@ function Range:parse() end append_param() + return self:validate() +end + +function Range:validate() + for _, param in ipairs(self.params) do + if not param:validate() then + return false + end + end + + return true end function Range:hit_test(cursor)