1

Split param and cells into different files

This commit is contained in:
Alex Yatskov 2025-01-19 19:35:37 -08:00
parent 67ba6c75af
commit 4acd690d9e
3 changed files with 102 additions and 97 deletions

View File

@ -1,100 +1,5 @@
local ParamCursorCell = {}
ParamCursorCell.__index = ParamCursorCell
function ParamCursorCell.new(cursor)
local cell = {cursor = cursor}
return setmetatable(cell, ParamCursorCell)
end
function ParamCursorCell:write(builder)
builder:write(self.cursor:get_value())
end
function ParamCursorCell:hit_test(cursor)
if self.cursor == cursor then
return {{char = self.cursor:get_value(), type = 'cursor_cell'}}
end
end
function ParamCursorCell:hit_search(trace, depth)
local frame = trace[depth]
assert(frame.type == 'cursor_cell')
assert(frame.char == self.cursor:get_value())
assert(depth == #trace)
return self
end
function ParamCursorCell:is_before_cursor(cursor)
return self.cursor < cursor
end
function ParamCursorCell:is_after_cursor(cursor)
return self.cursor > cursor
end
function ParamCursorCell:get_start_cursor()
return self.cursor
end
function ParamCursorCell:get_stop_cursor()
return self.cursor
end
function ParamCursorCell:is_empty()
return not self.cursor:get_value():match('%S')
end
local ParamRangeCell = {}
ParamRangeCell.__index = ParamRangeCell
function ParamRangeCell.new(range)
local cell = {range = range}
return setmetatable(cell, ParamRangeCell)
end
function ParamRangeCell:write(builder, wrapped)
self.range:write(builder, wrapped)
end
function ParamRangeCell:hit_test(cursor)
local trace = self.range:hit_test(cursor)
if trace then
table.insert(trace, 1, {type = 'range_cell'})
return trace
end
end
function ParamRangeCell:is_before_cursor(cursor)
return self.range.start_cursor < cursor
end
function ParamRangeCell:is_after_cursor(cursor)
return self.range.stop_cursor > cursor
end
function ParamRangeCell:hit_search(trace, depth)
local frame = trace[depth]
assert(frame.type == 'range_cell')
if depth == #trace then
return self
else
return self.range:hit_search(trace, depth + 1)
end
end
function ParamRangeCell:get_start_cursor()
return self.range.start_cursor
end
function ParamRangeCell:get_stop_cursor()
return self.range.stop_cursor
end
function ParamRangeCell:is_empty()
return false
end
ParamCursorCell = require('argonaut.param_cursor_cell')
ParamRangeCell = require('argonaut.param_range_cell')
local Param = {}
Param.__index = Param

View File

@ -0,0 +1,48 @@
local ParamCursorCell = {}
ParamCursorCell.__index = ParamCursorCell
function ParamCursorCell.new(cursor)
local cell = {cursor = cursor}
return setmetatable(cell, ParamCursorCell)
end
function ParamCursorCell:write(builder)
builder:write(self.cursor:get_value())
end
function ParamCursorCell:hit_test(cursor)
if self.cursor == cursor then
return {{char = self.cursor:get_value(), type = 'cursor_cell'}}
end
end
function ParamCursorCell:hit_search(trace, depth)
local frame = trace[depth]
assert(frame.type == 'cursor_cell')
assert(frame.char == self.cursor:get_value())
assert(depth == #trace)
return self
end
function ParamCursorCell:is_before_cursor(cursor)
return self.cursor < cursor
end
function ParamCursorCell:is_after_cursor(cursor)
return self.cursor > cursor
end
function ParamCursorCell:get_start_cursor()
return self.cursor
end
function ParamCursorCell:get_stop_cursor()
return self.cursor
end
function ParamCursorCell:is_empty()
return not self.cursor:get_value():match('%S')
end
return ParamCursorCell

View File

@ -0,0 +1,52 @@
local ParamRangeCell = {}
ParamRangeCell.__index = ParamRangeCell
function ParamRangeCell.new(range)
local cell = {range = range}
return setmetatable(cell, ParamRangeCell)
end
function ParamRangeCell:write(builder, wrapped)
self.range:write(builder, wrapped)
end
function ParamRangeCell:hit_test(cursor)
local trace = self.range:hit_test(cursor)
if trace then
table.insert(trace, 1, {type = 'range_cell'})
return trace
end
end
function ParamRangeCell:is_before_cursor(cursor)
return self.range.start_cursor < cursor
end
function ParamRangeCell:is_after_cursor(cursor)
return self.range.stop_cursor > cursor
end
function ParamRangeCell:hit_search(trace, depth)
local frame = trace[depth]
assert(frame.type == 'range_cell')
if depth == #trace then
return self
else
return self.range:hit_search(trace, depth + 1)
end
end
function ParamRangeCell:get_start_cursor()
return self.range.start_cursor
end
function ParamRangeCell:get_stop_cursor()
return self.range.stop_cursor
end
function ParamRangeCell:is_empty()
return false
end
return ParamRangeCell