detached d3a4767

interactive: drain key bursts before redrawing

A drag-drop into VS Code's terminal arrives as a stream of single
KeyRune events (no bracketed paste). The main loop redrew between
every rune, so on a long session the path appeared to type in over
several seconds instead of landing instantly.

Bump the input channel buffer to 256 and, after handling one key,
non-blockingly drain every other key already queued before
issuing one invalidate. The whole burst processes in a single
main-loop pass and the screen repaints once at the end.
commit
d3a4767ee6a0fad351261aa251a10ac82d7f27b9
author
patriceckhart · · 2026-04-28 12:21 UTC
parent
ef7327c
signature
unsigned
refs
tag: v0.1.38
1 file · +21 -2
M internal/agent/modes/interactive.go +21 -2
@@ -382,8 +382,11 @@ func (i *Interactive) Run(ctx context.Context) error {
382382 i.dialog.Open(i.cfg.ZotHome)
383383 }
384384
385- // Input goroutine.
386- keys := make(chan tui.Key, 8)
385+ // Input goroutine. Buffered generously so a drag-drop that the
386+ // terminal delivers as a burst of single-character key events
387+ // (no bracketed paste) can be drained in one main-loop pass
388+ // instead of triggering a redraw per character.
389+ keys := make(chan tui.Key, 256)
387390 go func() {
388391 reader := tui.NewReaderWithPeek(term.ReadByte, term.PeekByteTimeout)
389392 for {
@@ -476,6 +479,22 @@ func (i *Interactive) Run(ctx context.Context) error {
476479 if done := i.handleKey(ctx, k); done {
477480 return nil
478481 }
482+ // Drain any keystrokes that arrived during this iteration.
483+ // VS Code (and other terminals that don't bracket drops as
484+ // paste) deliver a path one rune at a time — without this
485+ // loop the editor would render between every rune and a
486+ // long path on a heavy transcript would visibly type in.
487+ drain:
488+ for {
489+ select {
490+ case k2 := <-keys:
491+ if done := i.handleKey(ctx, k2); done {
492+ return nil
493+ }
494+ default:
495+ break drain
496+ }
497+ }
479498 i.invalidate()
480499 case ev := <-authEvents:
481500 i.handleAuthEvent(ev)
@@ -382,8 +382,11 @@ func (i *Interactive) Run(ctx context.Context) error {
382 i.dialog.Open(i.cfg.ZotHome)382 i.dialog.Open(i.cfg.ZotHome)
383 }383 }
384 384
385- // Input goroutine.385+ // Input goroutine. Buffered generously so a drag-drop that the
386- keys := make(chan tui.Key, 8)386+ // terminal delivers as a burst of single-character key events
387+ // (no bracketed paste) can be drained in one main-loop pass
388+ // instead of triggering a redraw per character.
389+ keys := make(chan tui.Key, 256)
387 go func() {390 go func() {
388 reader := tui.NewReaderWithPeek(term.ReadByte, term.PeekByteTimeout)391 reader := tui.NewReaderWithPeek(term.ReadByte, term.PeekByteTimeout)
389 for {392 for {
@@ -476,6 +479,22 @@ func (i *Interactive) Run(ctx context.Context) error {
476 if done := i.handleKey(ctx, k); done {479 if done := i.handleKey(ctx, k); done {
477 return nil480 return nil
478 }481 }
482+ // Drain any keystrokes that arrived during this iteration.
483+ // VS Code (and other terminals that don't bracket drops as
484+ // paste) deliver a path one rune at a time — without this
485+ // loop the editor would render between every rune and a
486+ // long path on a heavy transcript would visibly type in.
487+ drain:
488+ for {
489+ select {
490+ case k2 := <-keys:
491+ if done := i.handleKey(ctx, k2); done {
492+ return nil
493+ }
494+ default:
495+ break drain
496+ }
497+ }
479 i.invalidate()498 i.invalidate()
480 case ev := <-authEvents:499 case ev := <-authEvents:
481 i.handleAuthEvent(ev)500 i.handleAuthEvent(ev)

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close