Skip to content

Fixed issue #1379: Redundant focused-node assignment ended node editing during keyboard navigation - #1387

Open
TetzkatLipHoka wants to merge 1 commit into
JAM-Software:masterfrom
TetzkatLipHoka:fix/issue-1379-refocus
Open

Fixed issue #1379: Redundant focused-node assignment ended node editing during keyboard navigation#1387
TetzkatLipHoka wants to merge 1 commit into
JAM-Software:masterfrom
TetzkatLipHoka:fix/issue-1379-refocus

Conversation

@TetzkatLipHoka

Copy link
Copy Markdown
Contributor

Fixes #1379, implementing the check @joachimmarder suggested in the issue discussion ("I wonder if this check if FocusedNode <> Node should be part of SetFocusedNode()") — yes, it works there, and this PR adds it with a regression test.

Cause

Keyboard navigation sets the focused node twice: WMKeyDown moves the focus (which fires OnFocusChanged), then AddToSelection() assigns the — by now unchanged — focused node again. SetFocusedNode() always ran DoFocusNode(), which begins by ending a node edit. An edit started by the application inside OnFocusChanged was therefore immediately ended again by that redundant assignment. With the mouse the event order differs, which is why the same handler worked there.

Fix

SetFocusedNode() exits early when the node is already focused, making the property setter free of side effects for a no-op assignment. DoFocusNode() itself is unchanged — its deliberate same-node handling (scroll into view, see the comment there) remains available to its direct callers.

Verification

New regression test Tests/VTFocusChangedIssue1379Tests.pas:

  • minimal contract: re-assigning the already focused node keeps tsEditing;
  • the reported scenario: an edit started in OnFocusChanged survives a real VK_DOWN key message, with the focus landing on the next node.

Both tests fail without the fix. Full suite: no new failures (the two TestCopyHTML failures also occur on unmodified master).

🤖 Generated with Claude Code

…d node editing during keyboard navigation

Keyboard navigation sets the focused node twice: WMKeyDown moves the
focus (which fires OnFocusChanged), then AddToSelection() assigns the
- by now unchanged - focused node again. SetFocusedNode() always ran
DoFocusNode(), which begins by ending a node edit. An edit started by
the application inside OnFocusChanged was therefore ended again right
away by that redundant assignment. With the mouse the event order
differs, which is why the same handler worked there.

Fix as suggested in the issue discussion: SetFocusedNode() exits early
when the node is already focused, so the property setter has no side
effects for a no-op assignment. DoFocusNode() itself is unchanged, its
deliberate same-node handling (scroll into view) remains available to
its direct callers.

New regression test Tests/VTFocusChangedIssue1379Tests.pas covers the
minimal contract (re-assigning the focused node keeps tsEditing) and
the reported scenario (edit started in OnFocusChanged survives a
VK_DOWN); both fail without the fix. Test suite: 2 pre-existing
failures (TestCopyHTML1/2, also failing on unmodified master), no new
failures.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

FocusChanged is called at wrong place when the user is using keyboard

1 participant