examples/split-editors: removing the focused last editor loses input focus
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:
- Start
go run ./split-editorsfromexamples/. - Press Tab to focus the second editor.
- Press Ctrl+W to remove it.
- Type a character: the remaining editor does not accept it.
- 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:
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
- 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.
Source: charmbracelet/bubbletea