charmbracelet / charmbracelet/bubbletea
examples/split-editors: removing the focused last editor loses input focus
- Dominant language
- Go
- Stars
- 44.9k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
### What happened?
In `examples/split-editors`, removing the currently focused last editor leaves
the surviving editor unfocused. Typing does nothing until Tab or Shift+Tab is
pressed. The remaining editor should receive focus immediately.
The remove handler truncates `m.inputs` and clamps `m.focus`, but does not call
`Focus()` on the surviving textarea. Its focus flag is still false after the
previous Tab operation. Removing a last editor that is not focused does not
have this problem.
### How can we reproduce this?
The existing example is the reproduction:
1. Start `go run ./split-editors` from `examples/`.
2. Press Tab to focus the second editor.
3. Press Ctrl+W to remove it.
4. Type a character: the remaining editor does not accept it.
5. Press Tab and type again: input works.
I verified the model transition directly, without a live terminal, using an
audit test in the example package. This small test expresses the expected
behavior and fails on the current source:
```go
func TestRemoveFocusedEditor(t *testing.T) {
m := newModel()
next, _ := m.Update(tea.KeyPressMsg{Code: tea.KeyTab})
m = next.(model)
next, _ = m.Update(tea.KeyPressMsg{Code: 'w', Mod: tea.ModCtrl})
m = next.(model)
next, _ = m.Update(tea.KeyPressMsg{Code: 'x', Text: "x"})
m = next.(model)
if got := m.inputs[0].Value(); got != "x" {
t.Fatalf("surviving editor value = %q, want x", got)
}
}
```
Use `package main` with imports `testing` and
`tea "charm.land/bubbletea/v2"`. The observed focus states are
`[true,false]` → `[false,true]` → `[false]`; pressing Tab restores `[true]`.
The symptom-and-recovery test passed ten repetitions, delivering characters
through the example's `model.Update` method.
### Which version of bubbletea are you using?
Current main `73b6d91ac1c3854dd4af046ab5f9e51d3b3b4290`, with the checked-in
examples module (`charm.land/bubbles/v2 v2.1.0` and local Bubble Tea replacement).
Go 1.26.3 on Windows/amd64; readonly module mode.
### Which terminals did you reproduce this with?
No terminal emulator, SSH or tmux was involved in the automated reproduction:
it calls the model update path with key messages. The interactive steps above
describe the corresponding example behavior, not an additional live-terminal
test claim.
### Search
- [x] Searched open and closed issues, PRs and discussions for split-editors,
editor focus and focus/removal. #366/#406 concern resizing, #1157 concerns
duplicated initial rendering, and #362/#1267 change styles rather than focus
recovery. No equivalent fix was found.
Contributor guide
Research direction
Start in examples/split-editors at the model.Update remove handler, where m.inputs and m.focus are updated. Run the provided audit test against the example package, then verify that removing the focused last editor leaves the surviving textarea focused and accepts input immediately.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100