Skip to content

Commit 1b467c4

Browse files
committed
Added :onSelect to Tables
1 parent a9458ea commit 1b467c4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/elements/Program.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ function BasaltProgram:resume(event, ...)
159159
if errorCallback then
160160
local trace = debug.traceback(self.coroutine, result)
161161
trace = trace == nil and "" or trace
162+
result = result or "Unknown error"
162163
local _result = errorCallback(self.program, result, trace:gsub(result, ""))
163164
if(_result==false)then
164165
self.filter = nil

src/elements/Table.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,19 @@ function Table:mouse_click(button, x, y)
144144
if relY > 1 then
145145
local rowIndex = relY - 2 + self.get("scrollOffset")
146146
if rowIndex >= 0 and rowIndex < #self.get("data") then
147-
self.set("selectedRow", rowIndex + 1)
147+
local newIndex = rowIndex + 1
148+
self.set("selectedRow", newIndex)
149+
self:fireEvent("select", newIndex, self.get("data")[newIndex])
148150
end
149151
end
150-
151152
return true
152153
end
153154

155+
function Table:onSelect(callback)
156+
self:registerCallback("select", callback)
157+
return self
158+
end
159+
154160
--- @shortDescription Handles scrolling through the table data
155161
--- @param direction number The scroll direction (-1 up, 1 down)
156162
--- @param x number The x position of the scroll

0 commit comments

Comments
 (0)