Skip to content

fix(ui): stop a held left at the resource list - #47

Open
junior wants to merge 3 commits into
p10node:mainfrom
junior:held-left-stops-at-list
Open

junior wants to merge 3 commits into
p10node:mainfrom
junior:held-left-stops-at-list

Conversation

@junior

@junior junior commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

A held left now stops at the resource list instead of going on to fold the group there.

Left in the main pane moves focus to the resource list (#46), and left in the list folds the group under the cursor, a choice saved to the config. A terminal sends a held key's repeats as fresh presses, so one long press of left went main pane -> list -> folded group, as pierreneter noted in the review of #46.

A left that comes within 750 ms of the one that moved focus, with no other key or click between, now counts as the same key still held down and folds nothing: the first repeat comes after the keyboard's repeat delay, 0.5 s on macOS by default and 660 ms in the X server's defaults. The rest follow at the repeat rate, many times a second, so once a repeat has come, a left counts as held only within 150 ms of the one before. A left after a pause, another key or a click folds as before, and so does left pressed with the list already focused. It is the same kind of window as the double-click one: Bubble Tea 1.x reports a repeat exactly like a press, so timing is all there is to go on.

Limits: a deliberate second left within 750 ms of the first is ignored too, as it cannot be told from a first repeat, so folding right after arriving takes a pause or a third tap (space folds at once). A keyboard set to wait longer than 750 ms before repeating still folds, and so does a gap of 150 ms or more between repeats, from a keyboard that repeats that slowly or a slow link that holds the repeats back.

The other note in that review, tab and shift+tab reaching the list while zoomed, is older than #46 and is not touched here.

keybindings.md and ui.md say a held left stops at the list. The README table and the in-app help stay as they are: a fresh left still folds.

Tests in internal/ui, on a model clock that the tests step by hand, each first checking that its group starts open: TestHeldLeftStopsAtTheResourceList (a first repeat just inside 750 ms, then ten more each just inside 150 ms), TestTappedLeftFoldsByTheThirdTap (taps 0.3 s apart), TestLeftFoldsAgainAfterAPause, TestAnotherKeyEndsAHeldLeft, TestClickEndsAHeldLeft and TestLeftInTheResourceListFoldsAtOnce. Cutting out any one piece of the change makes a test fail: the guard in the list, the refresh, the stamp in the main pane, the reset on another key or on a click, the short window, or the long one for the first repeat, and so does stamping from the real clock. gofmt, vet and go test -short ./... pass on Go 1.26.11 and 1.27.4, and so do -race on ., internal/k8s and internal/ui and govulncheck on 1.27.4, on the branch and merged onto main.

Left in the main pane moves focus to the resource list, and left there
folds the group under the cursor, a choice saved to the config. A
terminal sends a held key's repeats as fresh presses, so one long press
of left went main pane -> list -> folded group, as pierreneter noted in
the review of p10node#46.

A left that comes within 750 ms of the one that moved focus, with no
other key between, now counts as the same key still held down and folds
nothing, and each such repeat restarts the 750 ms. The first repeat
comes after the keyboard's repeat delay, 0.5 s on macOS by default and
660 ms in the X server's defaults, and the rest follow many times a
second. A left after a pause or after any other key folds as before, and
so does left pressed with the list already focused.

Two limits: a deliberate second left within 750 ms of the first is
ignored too, so folding right after arriving takes a short pause (space
folds at once), and a keyboard set to wait longer than 750 ms before
repeating still folds. Bubble Tea 1.x reports a repeat exactly like a
press, so timing is all there is to go on.

Signed-off-by: Adao Oliveira Jr <[email protected]>
@junior
junior requested a review from pierreneter as a code owner November 21, 2026 07:23

@Devehab Devehab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gofmt, go vet ./internal/ui/ and go test ./internal/ui/ pass for me on 2b14837, and the guard reads right: a zero leftHeldAt makes now.Sub huge, so a left with the list already focused folds right away.

One more limit next to the two you listed: a slow repeat rate folds too. The window restarts on every repeat, so if the repeats themselves come more than 750 ms apart, the second one lands outside it. I tried it with a scratch test (first repeat at half the window, the next one 900 ms later) and the group folded. That only hits a very slow repeat setting, so I don't think it needs more than maybe a word in the docs.

For later: Bubble Tea v2 reports repeats directly (IsRepeat on the key, with the Kitty keyboard protocol's event types or the Windows console). If k10s moves to v2, this could use that where the terminal supports it and keep the timing as the fallback.

@junior

junior commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for checking it, @Devehab, and for the scratch test. You're right about a slow repeat rate: each repeat restarts the window, so if the repeats themselves come more than 750 ms apart, the second one folds. I'll leave that as it is. A repeat that late looks exactly like a fresh press, which the docs already say folds, and it takes a very slow repeat setting to get there.

Agreed on Bubble Tea v2 for later: there a key event says whether it is a repeat (IsRepeat, with the Kitty keyboard protocol or the Windows console), so if k10s moves to v2 the timing can stay as the fallback for terminals that don't report repeats.

@pierreneter pierreneter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. The guard does what it says at default repeat settings, and a fold that gets saved was worth stopping.

One behaviour change is worth addressing before merge: deliberate taps of left are now swallowed for as long as they keep coming (first inline comment). The other inline comments are smaller and can be follow-ups.

Two things that are not from this PR, noted so they are not lost:

  • Holding enter in the resource list has the same shape as the bug fixed here: it moves focus to the main pane and its repeats go on to openSelected(). The guard could later cover whichever key moved focus, not only left.
  • While zoomed, tab / shift+tab still reach the off-screen resource list (focusNext does not look at m.zoomed), where left or space folds a group nobody can see.

Comment thread internal/ui/model.go Outdated
Comment on lines +1479 to +1482
if now := time.Now(); now.Sub(m.leftHeldAt) < heldKeyWindow {
m.leftHeldAt = now
return nil
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also swallows deliberate presses, and because every swallowed press restarts the window, tapping never gets through. From the main pane, left, left, left about 300 ms apart leaves the group open until there is a 750 ms pause or another key. Before this PR the second tap folded, and nothing tells the user a press was ignored.

The 750 ms is only needed to wait out the repeat delay. After the first repeat has arrived, the rest come at the repeat rate (tens of ms), so a much shorter window is enough from then on:

window := heldKeyWindow // waiting out the repeat delay
if m.leftRepeating {
	window = heldRepeatWindow // ~150 ms: repeats come many times a second
}
if now := time.Now(); now.Sub(m.leftHeldAt) < window {
	m.leftHeldAt, m.leftRepeating = now, true
	return nil
}

with leftRepeating cleared wherever leftHeldAt is. A second tap inside 750 ms still cannot be told from the first repeat, but the third one then folds instead of re-arming the window forever.

Comment thread internal/ui/model.go
// default, 660 ms in the X server's defaults), then many times a second.
// Without it, one long press of left in the main pane would move focus to the
// resource list and then fold the group there, a choice that is saved.
const heldKeyWindow = 750 * time.Millisecond

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a regression, but the margin is thin. The X default quoted above (660 ms) sits only 90 ms inside the window, and longer repeat-delay settings fall outside it: Windows offers 750 ms and 1 s, and as far as I know the long end of the macOS "Delay Until Repeat" slider is about 1 s and up. On those a held left still folds the group and saves it.

A wider window would cover more of them. On its own that makes the swallowed-tap problem above worse, but with a separate short window for the repeats it costs much less. Otherwise a line here saying which settings are knowingly not covered would do.

Comment thread internal/ui/interaction_test.go Outdated
// Each repeat comes a little inside the window after the one before: a
// long press lasts as long as it keeps repeating, not one window in all.
for i := 0; i < 2; i++ {
m.leftHeldAt = m.leftHeldAt.Add(-heldKeyWindow * 4 / 5)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This depends on the real clock. The stamp is rewound by 600 ms, so the test passes only if time.Now() inside handleKey lands within the remaining 150 ms, twice. A stalled runner (a GC pause under -race, CPU steal on a shared VM) would fold the group and fail the test for no real reason.

A clock on the model (m.now func() time.Time) driven from the tests would make all four deterministic. A smaller rewind would also widen the margin.

Comment thread internal/ui/interaction_test.go Outdated
m := newTestModel(t, mock.New(""))
dismissOnboarding(m)
m.focus = focusMain
g := m.curKind().Group

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test, TestAnotherKeyEndsAHeldLeft and TestLeftInTheResourceListFoldsAtOnce only check m.collapsed[g] afterwards. They do not have the "starts open" precondition the first test has. If the mock's first kind ever lands in one of defaultCollapsedGroups, all three pass without left doing anything. The same if m.collapsed[g] { t.Fatalf(...) } up front would close that.

Comment thread internal/ui/model.go
Comment on lines +1307 to +1309
if key != "left" {
m.leftHeldAt = time.Time{} // any other key ends a held left
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: only key presses clear the stamp, handleMouse does not. left in the main pane, then a click on a kind in another group within the window, then left to fold that group: the press is swallowed. Clearing leftHeldAt on a button press in handleMouse would cover it.

pierreneter's review of p10node#47: every left the guard swallowed restarted
the 750 ms, so tapping left from the main pane, say three times 0.3 s
apart, never folded the group until a pause or another key. Before p10node#47
the second tap folded.

The 750 ms is only needed to wait out the keyboard's repeat delay. Once
the first repeat has come, the rest follow at the repeat rate, many
times a second, so from then on a left counts as held only within
150 ms of the one before. A second tap inside the 750 ms still cannot
be told from the first repeat and folds nothing, but the third now
folds. The window is measured as each press arrives, so a gap of over
150 ms between repeats now folds with the key still down, whether the
keyboard repeats that slowly or a slow link holds the repeats back.
Before, it took a gap of 750 ms.

Also from the review: a click ends a held left, as any other key does,
so left right after clicking a kind in another group folds that group;
the guard reads its clock through m.now, and the tests step a fake one
instead of racing the real clock; each held-left test first checks
that its group starts open; and the comment on heldKeyWindow says that
a keyboard set to wait longer than 750 ms before repeating is knowingly
not covered.

Signed-off-by: Adao Oliveira Jr <[email protected]>
@junior

junior commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, @pierreneter. All five are in af00c10, a new commit on top of 2b14837:

  • Taps: your two windows. Once the first repeat has come, a left counts as held only within 150 ms of the one before (heldRepeatWindow), so taps 0.3 s apart fold on the third. The cost is the other side of Devehab's note: a gap of 150 ms or more between repeats now folds with the key still down (a keyboard that repeats that slowly, or a slow link), where before it took 750 ms.
  • The 750 ms stays, and its comment now says that a keyboard set to wait longer before repeating is knowingly not covered. A wider window would take more second taps for a first repeat.
  • The guard reads the time through m.now, so the tests step a fake clock by hand; each held-left test first checks that its group starts open; and a click ends a held left like any other key, with TestClickEndsAHeldLeft for your click-then-left case.

Each piece of the guard has a test that fails without it, and the branch passes the full gate on Go 1.26.11 and 1.27.4, merged onto main as well. Of the two notes outside this PR, the held enter now has an issue of its own, #53, and Devehab's #52 takes on the zoomed tab.

@Devehab Devehab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked af00c10. gofmt, go vet ./internal/ui/ and go test ./internal/ui/ pass for me.

The new tests catch what they're for. With heldRepeatWindow set back to 750 ms, TestTappedLeftFoldsByTheThirdTap fails (three taps 300 ms apart fold nothing). Without the endHeldLeft() in handleMouse, TestClickEndsAHeldLeft fails. New is the only place that builds a Model, so now is always set outside the tests that swap it.

Keeping leftHeldAt and leftRepeating behind startHeldLeft/endHeldLeft reads well too, so nothing can reset one and forget the other.

@pierreneter pierreneter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the effort on this, and for taking every point from the last round so carefully. All five are addressed in af00c10: the two windows let taps through again, the model clock makes the tests deterministic, and the click reset and the "starts open" checks close the gaps.

I merged the branch onto current main locally and ran the full gate there: gofmt, vet, go test -short ./... on Go 1.26.11 and 1.27.4, -race on ., internal/k8s and internal/ui, and govulncheck. All pass, and each piece of the guard has a test that fails without it.

Thanks also for splitting the two side notes out into #52 and #53.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants