mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
Enhance TextInput and filtering functionality in ConfirmingPage
- Added support for onChanged event in TextInput to handle real-time text updates. - Updated ConfirmingPage to utilize onChanged for filter input, improving user interaction. - Refactored wildcard matching function in PatchVisualizer to support case-insensitive substring matching, enhancing filtering capabilities.
This commit is contained in:
parent
c092bb975c
commit
e124d8a227
3 changed files with 24 additions and 14 deletions
|
|
@ -15,30 +15,32 @@ local e = Roact.createElement
|
|||
|
||||
local DomLabel = require(script.DomLabel)
|
||||
|
||||
-- Convert wildcard pattern (with *) to case-insensitive match
|
||||
-- e.g., "player*sync" matches "PlayerDataSync"
|
||||
local function matchesWildcard(name: string, pattern: string): boolean
|
||||
if pattern == "" then
|
||||
-- Case-insensitive substring match with wildcard support
|
||||
-- * = one or more characters (.+ in regex)
|
||||
-- e.g., "player" matches "PlayerDataSync", "MyPlayer", etc.
|
||||
-- e.g., "player*sync" matches "PlayerDataSync" but not "PlayerSync"
|
||||
local function matchesFilter(name: string, filter: string): boolean
|
||||
if filter == "" then
|
||||
return true
|
||||
end
|
||||
|
||||
-- Escape Lua pattern special chars except *
|
||||
local escaped = pattern:gsub("([%.%+%-%?%^%$%(%)%[%]%%])", "%%%1")
|
||||
-- Convert * to .* (match any characters)
|
||||
local luaPattern = "^" .. escaped:gsub("%*", ".*") .. "$"
|
||||
local escaped = filter:gsub("([%.%+%-%?%^%$%(%)%[%]%%])", "%%%1")
|
||||
-- Convert * to .+ (one or more characters)
|
||||
local pattern = escaped:gsub("%*", ".+")
|
||||
|
||||
return string.match(name:lower(), luaPattern:lower()) ~= nil
|
||||
return string.match(name:lower(), pattern:lower()) ~= nil
|
||||
end
|
||||
|
||||
-- Check if node or any of its descendants match the filter
|
||||
local function nodeOrDescendantMatches(node, pattern: string): boolean
|
||||
if matchesWildcard(node.name or "", pattern) then
|
||||
local function nodeOrDescendantMatches(node, filter: string): boolean
|
||||
if matchesFilter(node.name or "", filter) then
|
||||
return true
|
||||
end
|
||||
|
||||
if node.children then
|
||||
for _, child in node.children do
|
||||
if type(child) == "table" and nodeOrDescendantMatches(child, pattern) then
|
||||
if type(child) == "table" and nodeOrDescendantMatches(child, filter) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -108,7 +108,15 @@ function TextInput:render()
|
|||
end,
|
||||
|
||||
[Roact.Event.FocusLost] = function(rbx)
|
||||
self.props.onEntered(rbx.Text)
|
||||
if self.props.onEntered then
|
||||
self.props.onEntered(rbx.Text)
|
||||
end
|
||||
end,
|
||||
|
||||
[Roact.Change.Text] = function(rbx)
|
||||
if self.props.onChanged then
|
||||
self.props.onChanged(rbx.Text)
|
||||
end
|
||||
end,
|
||||
}),
|
||||
Children = Roact.createFragment(self.props[Roact.Children]),
|
||||
|
|
|
|||
|
|
@ -142,12 +142,12 @@ function ConfirmingPage:render()
|
|||
|
||||
FilterInput = e(TextInput, {
|
||||
text = self.state.filterText,
|
||||
placeholder = "Filter (* = wildcard)",
|
||||
placeholder = "Filter",
|
||||
enabled = true,
|
||||
transparency = self.props.transparency,
|
||||
size = UDim2.new(0.5, -5, 1, 0),
|
||||
position = UDim2.new(0.5, 5, 0, 0),
|
||||
onEntered = function(text)
|
||||
onChanged = function(text)
|
||||
self:setState({ filterText = text })
|
||||
end,
|
||||
}),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue