-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Focus the viewpane on the next tick #2903
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bba0bb0
Call base focus method at the next tick
lionel- 069755b
Add comment for the `useCallback()` usage
lionel- 2652e9e
Gather all focus fixes in `PositronViewPane` class
lionel- 7a6cb24
Update src/vs/workbench/browser/positronViewPane/positronViewPane.ts
lionel- File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/vs/workbench/browser/positronViewPane/positronViewPane.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (C) 2024 Posit Software, PBC. All rights reserved. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { disposableTimeout } from 'vs/base/common/async'; | ||
import { DisposableStore } from 'vs/base/common/lifecycle'; | ||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; | ||
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; | ||
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; | ||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; | ||
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; | ||
import { IOpenerService } from 'vs/platform/opener/common/opener'; | ||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; | ||
import { IThemeService } from 'vs/platform/theme/common/themeService'; | ||
import { IViewPaneOptions, ViewPane } from 'vs/workbench/browser/parts/views/viewPane'; | ||
import { IViewDescriptorService } from 'vs/workbench/common/views'; | ||
|
||
export abstract class PositronViewPane extends ViewPane { | ||
private _disposableStore: DisposableStore; | ||
|
||
/** | ||
* Drive focus to an element inside the view. | ||
* Called automatically by `focus()`. | ||
*/ | ||
focusElement?(): void; | ||
|
||
constructor( | ||
options: IViewPaneOptions, | ||
@IKeybindingService keybindingService: IKeybindingService, | ||
@IContextMenuService contextMenuService: IContextMenuService, | ||
@IConfigurationService configurationService: IConfigurationService, | ||
@IContextKeyService contextKeyService: IContextKeyService, | ||
@IViewDescriptorService viewDescriptorService: IViewDescriptorService, | ||
@IInstantiationService instantiationService: IInstantiationService, | ||
@IOpenerService openerService: IOpenerService, | ||
@IThemeService themeService: IThemeService, | ||
@ITelemetryService telemetryService: ITelemetryService, | ||
) { | ||
super( | ||
options, | ||
keybindingService, | ||
contextMenuService, | ||
configurationService, | ||
contextKeyService, | ||
viewDescriptorService, | ||
instantiationService, | ||
openerService, | ||
themeService, | ||
telemetryService | ||
); | ||
this._disposableStore = this._register(new DisposableStore()); | ||
|
||
// Make the viewpane focusable even when there are no components | ||
// available to take the focus. The viewpane must be able to take focus | ||
// at all times because otherwise blurring events do not occur and the | ||
// viewpane management state becomes confused on toggle. | ||
this.element.tabIndex = 0; | ||
} | ||
|
||
override focus(): void { | ||
// We focus at the next tick because in some cases `focus()` is called | ||
// when the viewpane is not visible yet (don't trust `this.isBodyVisible()`). | ||
// In this case the `focus()` call fails (don't trust `this.onFocus()`). | ||
// This happens for instance with `workbench.action.togglePanel` or | ||
// `workbench.action.toggleSecondarySideBar`. Not doing it at the next tick | ||
// would result in broken viewpane toggling, see | ||
// https://github.com/posit-dev/positron/pull/2867 | ||
const focus = () => { | ||
// The base class focuses the whole pane (we set its tabIndex to make this possible). | ||
super.focus(); | ||
|
||
// Drive focus to an inner element if any. Also needs to be at the next tick, | ||
// and after the `super.focus()` call. | ||
this.focusElement?.(); | ||
}; | ||
disposableTimeout(focus, 0, this._disposableStore); | ||
} | ||
|
||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course this exists in
async.ts
! Good find!