address selection filter review feedback

This commit is contained in:
Yifan Chen
2026-09-12 00:08:08 -07:00
parent 37767b3bbc
commit bae986e90b
5 changed files with 32 additions and 32 deletions
+15
View File
@@ -18,6 +18,21 @@ debug('Trace: PASTE')
warn_once_set = WeakSet()
def filter_ui_choices(choices: list[str], preferences: list[str] | None = None, selected: str | None = None) -> tuple[list[str], bool]:
"""Return display choices while preserving the current selection."""
available = list(dict.fromkeys(choices))
preferred = set(preferences or [])
filtered = [choice for choice in available if choice in preferred]
if not filtered:
return available, False
if selected in available and selected not in filtered:
filtered.append(selected)
if 'None' in filtered:
filtered.remove('None')
filtered.insert(0, 'None')
return filtered, len(filtered) < len(available)
def gr_show(visible=True):
return {"visible": visible, "__type__": "update"}