1
This commit is contained in:
Alex Yatskov 2025-01-18 19:11:04 -08:00
parent 711e800226
commit 726577ee00
2 changed files with 29 additions and 16 deletions

View File

@ -12,11 +12,17 @@ end
function ParamCursorCell:hit_test(cursor) function ParamCursorCell:hit_test(cursor)
if self.cursor == cursor then if self.cursor == cursor then
return {} return {{
type = 'cursor_cell',
value = self.cursor:get_value(),
}}
end end
end end
function ParamCursorCell:hit_search() function ParamCursorCell:hit_search(trace, depth)
local frame = trace[depth]
assert(frame.type == 'cursor_cell')
return self.cursor return self.cursor
end end
@ -32,10 +38,6 @@ function ParamCursorCell:is_empty()
return not self.cursor:get_value():match('%S') return not self.cursor:get_value():match('%S')
end end
function ParamCursorCell:get_type()
return 'cursor'
end
local ParamRangeCell = {} local ParamRangeCell = {}
ParamRangeCell.__index = ParamRangeCell ParamRangeCell.__index = ParamRangeCell
@ -49,11 +51,18 @@ function ParamRangeCell:write(builder, wrapped)
end end
function ParamRangeCell:hit_test(cursor) function ParamRangeCell:hit_test(cursor)
return self.range:hit_test(cursor) local trace = self.range:hit_test(cursor)
if trace then
table.insert(trace, 1, {type = 'range_cell'})
return trace
end
end end
function ParamRangeCell:hit_search(trace, depth) function ParamRangeCell:hit_search(trace, depth)
return self.range:hit_search(trace, depth) local frame = trace[depth]
assert(frame.type == 'range_cell')
return self.range:hit_search(trace, depth + 1)
end end
function ParamRangeCell:get_start_row() function ParamRangeCell:get_start_row()
@ -68,10 +77,6 @@ function ParamRangeCell:is_empty()
return false return false
end end
function ParamRangeCell:get_type()
return 'range'
end
local Param = {} local Param = {}
Param.__index = Param Param.__index = Param
@ -108,8 +113,7 @@ function Param:hit_test(cursor)
table.insert(trace, 1, { table.insert(trace, 1, {
index = i, index = i,
length = #self.cells, length = #self.cells,
subtype = cell:get_type(), type = 'param_cell',
type='param_cell',
}) })
return trace return trace
@ -119,6 +123,10 @@ end
function Param:hit_search(trace, depth) function Param:hit_search(trace, depth)
local frame = trace[depth] local frame = trace[depth]
assert(frame.index <= #self.cells)
assert(frame.length == #self.cells)
assert(frame.type == 'param_cell')
return self.cells[frame.index]:hit_search(trace, depth + 1) return self.cells[frame.index]:hit_search(trace, depth + 1)
end end

View File

@ -111,8 +111,8 @@ function Range:hit_test(cursor)
table.insert(trace, 1, { table.insert(trace, 1, {
index = i, index = i,
length = #self.params, length = #self.params,
subtype = self.pairing.open,
type = 'range_param', type = 'range_param',
value = self.pairing.open,
}) })
return trace return trace
@ -122,14 +122,19 @@ function Range:hit_test(cursor)
return { return {
index = 0, index = 0,
length = #self.params, length = #self.params,
subtype = self.pairing.open,
type = 'range_padding', type = 'range_padding',
value = self.pairing.open,
} }
end end
end end
function Range:hit_search(trace, depth) function Range:hit_search(trace, depth)
local frame = 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)
if frame.index == 0 then if frame.index == 0 then
return self.start_cursor return self.start_cursor
else else