Make cf dropdown scroll instead of showing +N more
Arrow past the last visible item now scrolls the list smoothly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
df1d3ace23
commit
356a47eebc
|
|
@ -112,6 +112,7 @@ def run_picker() -> Optional[PickerResult]:
|
||||||
|
|
||||||
query = ""
|
query = ""
|
||||||
selected = 0
|
selected = 0
|
||||||
|
scroll = 0
|
||||||
last_drawn = 0
|
last_drawn = 0
|
||||||
|
|
||||||
print(HIDE_CURSOR, end='', flush=True)
|
print(HIDE_CURSOR, end='', flush=True)
|
||||||
|
|
@ -133,21 +134,28 @@ def run_picker() -> Optional[PickerResult]:
|
||||||
if selected >= len(filtered):
|
if selected >= len(filtered):
|
||||||
selected = max(0, len(filtered) - 1)
|
selected = max(0, len(filtered) - 1)
|
||||||
|
|
||||||
|
# Adjust scroll to keep selection visible
|
||||||
|
if selected < scroll:
|
||||||
|
scroll = selected
|
||||||
|
elif selected >= scroll + MAX_VISIBLE:
|
||||||
|
scroll = selected - MAX_VISIBLE + 1
|
||||||
|
|
||||||
# Clear previous
|
# Clear previous
|
||||||
if last_drawn:
|
if last_drawn:
|
||||||
clear_dropdown(last_drawn)
|
clear_dropdown(last_drawn)
|
||||||
|
|
||||||
# Draw
|
# Draw
|
||||||
visible = filtered[:MAX_VISIBLE]
|
visible = filtered[scroll:scroll + MAX_VISIBLE]
|
||||||
lines = []
|
lines = []
|
||||||
|
|
||||||
# Query line
|
# Query line
|
||||||
prompt = f"{DIM}>{RESET} {YELLOW}{query}{RESET}{'▌' if True else ''}"
|
prompt = f"{DIM}>{RESET} {YELLOW}{query}{RESET}▌"
|
||||||
lines.append(prompt)
|
lines.append(prompt)
|
||||||
|
|
||||||
# Items
|
# Items
|
||||||
for i, t in enumerate(visible):
|
for i, t in enumerate(visible):
|
||||||
if i == selected:
|
actual_idx = scroll + i
|
||||||
|
if actual_idx == selected:
|
||||||
prefix = f"{CYAN}{BOLD}▸ {t['name']}{RESET}"
|
prefix = f"{CYAN}{BOLD}▸ {t['name']}{RESET}"
|
||||||
else:
|
else:
|
||||||
prefix = f" {t['name']}"
|
prefix = f" {t['name']}"
|
||||||
|
|
@ -162,10 +170,6 @@ def run_picker() -> Optional[PickerResult]:
|
||||||
|
|
||||||
lines.append(prefix)
|
lines.append(prefix)
|
||||||
|
|
||||||
# Show count if more
|
|
||||||
if len(filtered) > MAX_VISIBLE:
|
|
||||||
lines.append(f"{DIM} ... +{len(filtered) - MAX_VISIBLE} more{RESET}")
|
|
||||||
|
|
||||||
# Print
|
# Print
|
||||||
sys.stdout.write('\n'.join(lines) + '\n')
|
sys.stdout.write('\n'.join(lines) + '\n')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
@ -204,10 +208,12 @@ def run_picker() -> Optional[PickerResult]:
|
||||||
elif ch == '\x7f' or ch == '\b': # Backspace
|
elif ch == '\x7f' or ch == '\b': # Backspace
|
||||||
query = query[:-1]
|
query = query[:-1]
|
||||||
selected = 0
|
selected = 0
|
||||||
|
scroll = 0
|
||||||
|
|
||||||
elif ch.isprintable():
|
elif ch.isprintable():
|
||||||
query += ch
|
query += ch
|
||||||
selected = 0
|
selected = 0
|
||||||
|
scroll = 0
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(SHOW_CURSOR, end='', flush=True)
|
print(SHOW_CURSOR, end='', flush=True)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue