Fix focus stolen from terminal when commit message prefix is updated#35
Open
thomasrepnik wants to merge 1 commit into
Open
Fix focus stolen from terminal when commit message prefix is updated#35thomasrepnik wants to merge 1 commit into
thomasrepnik wants to merge 1 commit into
Conversation
panel.setCommitMessage() calls CommitMessageUi.focus() in the platform's CommitProjectPanelAdapter, yanking focus into the commit message field on every branch change (e.g. git checkout in the terminal). Set the message directly on the CommitMessage component instead (no focus request) and skip the update entirely when the computed message is unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When the branch changes (e.g.
git checkoutin the IntelliJ terminal), the plugin updates the commit message prefix — but it also stole keyboard focus from the terminal and moved it into the commit message field.Root cause (verified against IntelliJ 2023.2.4 sources): the plugin called
CheckinProjectPanel.setCommitMessage(...), and the platform'sCommitProjectPanelAdapterimplements that assetText(...)followed bycommitMessageUi.focus()— in both the non-modal commit tool window and the modal commit dialog. The write also happened unconditionally on everyGIT_REPO_CHANGEevent (fetch, ticket-less branches), stealing focus even when nothing changed.Fix (only
CommitPrefixCheckinHandler.java):calculateNewCommitMessage(...)returningOptional.empty()when the branch has no ticket or the computed message is unchanged (compared right-trimmed, sinceCommitMessage.getText()trims trailing whitespace). No-op repo events now do nothing at all.setCommitMessageWithoutFocus(...): finds theCommitMessagecomponent viaUIUtil.findComponentOfType(panel.getComponent(), ...)and calls itssetCommitMessage(...), which only sets text and never requests focus. Falls back topanel.setCommitMessage(...)for unknown panel implementations.All prefix/ticket logic (
updatePrefix,getTicket, settings, listener wiring) is untouched. Manually verified: prefix still updates on terminal checkout, focus stays in the terminal.Note: bypassing the adapter also skips its
VcsConfiguration.saveCommitMessage(oldText)call, so intermediate prefix rewrites no longer pollute the "recent commit messages" history; the final message is still saved on commit.Test Coverage
10 new parameterized tests for
calculateNewCommitMessage(TDD: written first, confirmed failing, then implemented). Tests: 133 → 143 (+10 new), all passing.Coverage audit: 9/11 testable paths (82%). Remaining gaps are low-risk Optional-plumbing combinations (OTHER system with no-digit branch; blank-but-non-null current message) whose underlying logic is covered by existing
getTicket/updatePrefixtests.Pre-Landing Review
calculateNewCommitMessage_messageUnchanged_returnsEmpty(main/develop) exercise the no-ticket branch rather than message equality — cosmetic naming only.repositoryChangedignores its repository argument in multi-root projects.Test plan
./gradlew test— 143/143 pass (fresh run on merged state)./gradlew buildPlugin— builds successfullygit checkout <ticket-branch>in the IDE terminal updates the prefix without stealing focus🤖 Generated with Claude Code