Skip to content

Fix FocusManager to auto-focus next element when current element is removed#108

Merged
LittleLittleCloud merged 16 commits intomainfrom
copilot/fix-focus-manager-behavior
Nov 16, 2025
Merged

Fix FocusManager to auto-focus next element when current element is removed#108
LittleLittleCloud merged 16 commits intomainfrom
copilot/fix-focus-manager-behavior

Conversation

Copy link
Contributor

Copilot AI commented Nov 7, 2025

  • Understand the repository structure and focus manager implementation
  • Identify the root cause: OnNext method ignores the return value from UpdateFocusTargets_NoLock
  • Build and run existing tests to establish baseline
  • Create tests that reproduce the issue
  • Fix the OnNext method to handle focus change when element is removed
  • Verify the fix with tests
  • Run all tests to ensure no regressions
  • Address code review feedback about exception handling
  • Perform security scan - No vulnerabilities found
  • Add VDom Tree Debugging documentation
  • Remove Use Cases section from documentation per feedback
  • Clean up LoginForm example - remove FocusManager injection and focus key display
  • Fix code formatting issues

Recent Changes

  • Fixed code formatting by removing trailing whitespace in KeyboardEventManager.cs
  • All 96 tests passing on .NET 8.0, 9.0, and 10.0
Original prompt

This section details on the original issue you should resolve

<issue_title>Focus manager doesn't automatically focus to the next available element when the current focused element get removed from render list (for example, when the current focused element is in @if block that no longer satisfied)</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 7, 2025 16:44
Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix focus manager to handle element removal Fix FocusManager to auto-focus next element when current element is removed Nov 7, 2025
@LittleLittleCloud LittleLittleCloud marked this pull request as ready for review November 9, 2025 20:08
Copilot AI review requested due to automatic review settings November 9, 2025 20:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds automatic refocusing behavior to the FocusManager when the currently focused element is removed from the VDOM. The changes track the session's cancellation token and trigger focus adjustments asynchronously when the observer detects structural changes.

  • Stores _sessionCts to access cancellation tokens outside the session initialization
  • Modifies OnNext to detect when the focused element is removed and automatically refocus to the first available element
  • Adds two test cases covering automatic refocusing and focus clearing scenarios

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/RazorConsole.Core/Focus/FocusManager.cs Added _sessionCts field to track session cancellation token; modified OnNext to fire async focus changes via Task.Run when elements are removed
src/RazorConsole.Tests/FocusManagerTests.cs Added tests for automatic refocusing when focused element is removed and for clearing focus when all elements are removed

LittleLittleCloud and others added 3 commits November 9, 2025 12:11
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Xiaoyun Zhang <bigmiao.zhang@gmail.com>
@LittleLittleCloud LittleLittleCloud changed the title Fix FocusManager to auto-focus next element when current element is removed WIP Fix FocusManager to auto-focus next element when current element is removed Nov 10, 2025
@LittleLittleCloud LittleLittleCloud changed the title WIP Fix FocusManager to auto-focus next element when current element is removed Fix FocusManager to auto-focus next element when current element is removed Nov 16, 2025
Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
…ample

Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
@LittleLittleCloud
Copy link
Member

@copilot fix format

Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 16, 2025

@copilot fix format

Fixed code formatting by removing trailing whitespace in KeyboardEventManager.cs.

Commit: 927fb91

@LittleLittleCloud LittleLittleCloud enabled auto-merge (squash) November 16, 2025 15:51
@LittleLittleCloud LittleLittleCloud merged commit f9cb29d into main Nov 16, 2025
10 checks passed
@LittleLittleCloud LittleLittleCloud deleted the copilot/fix-focus-manager-behavior branch November 16, 2025 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants