fix(docs-ui): add auto-focus feature to fix white screen when switching documents #6094
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.
close #6086
Description
This PR fixes the white screen issue when switching document IDs by adding an auto-focus feature to the Docs UI plugin, matching the existing behavior in Sheets UI plugin.
Root Cause
When creating a new document with a different ID:
createUnit()sets the document as "current" but does NOT focus itfocused$eventfocusUnit()call, the render engine doesn't switch → white screenSolution
Added
_initAutoFocus()method to Docs UI plugin (similar to Sheets UI):getCurrentTypeOfUnit$changesfocusUnit()for new documentsdisableAutoFocusconfig option for flexibilityChanges
packages/docs-ui/src/plugin.ts
_initAutoFocus()method (6 lines, clean implementation)IUniverInstanceServicein constructoronReady()packages/docs-ui/src/controllers/config.schema.ts
disableAutoFocus?: booleanconfig optionDesign
Follows the exact same pattern as
packages/sheets-ui/src/plugin.ts(lines 295-300) for consistency and maintainability.How to Test
Before (white screen)
After (works automatically)
Test Steps
pnpm devOptional: Test disable auto-focus
Pull Request Checklist