Skip to content

fix(examples): restore focus after removing an editor - #1793

Open
dajiaohuang wants to merge 1 commit into
charmbracelet:mainfrom
dajiaohuang:fix/1792-restore-editor-focus
Open

fix(examples): restore focus after removing an editor#1793
dajiaohuang wants to merge 1 commit into
charmbracelet:mainfrom
dajiaohuang:fix/1792-restore-editor-focus

Conversation

@dajiaohuang

Copy link
Copy Markdown
  • I have read CONTRIBUTING.md.
  • New-feature discussion: not applicable (example bug fix).

Fixes #1792.

When Ctrl+W removes the focused last editor, the example moves m.focus to a
surviving textarea but leaves that textarea blurred. Characters are ignored
until another Tab/Shift+Tab restores focus.

Focus the surviving textarea when clamping the index and retain the command
returned by Focus(). Removing an unfocused last editor does not restart or
move the existing focus. No dependency, public API, or CI change.

The regression test covers two, three, and six editors, including removal with
first/middle/last focus. It checks the unique focused editor and that existing
content is preserved while the next character is accepted through model.Update.

Validation:

  • Before the fix, focused-last cases fail on both focus and input assertions;
    non-last controls pass.
  • After the fix, go test -count=10 -run '^TestRemoveEditorPreservesFocus$' ./split-editors
    from examples/ passes (Windows Go 1.26.3).
  • go test ./... in the examples module passes (examples without tests compile).
  • Root go test -race -count=4 -cpu=1,4 ./... passes (WSL Linux Go 1.26.6).
  • Root golangci-lint run and git diff --cached --check checked before submission.

Separate pre-existing limitation observed during the audit: the untouched
tutorials module requires go.mod updates for go test -mod=readonly ./....
This patch does not modify or claim to repair that module. No live terminal or
networked example was launched for this regression.

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.

examples/split-editors: removing the focused last editor loses input focus

1 participant