Skip to content

Commit 56614fb

Browse files
authored
Merge pull request microsoft#189074 from microsoft/merogge/focus-last-hover
focus hover on escape of accessible view so context isn't lost
2 parents 38a8373 + 75c8905 commit 56614fb

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

src/vs/workbench/contrib/accessibility/browser/accessibility.contribution.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { getNotificationFromContext } from 'vs/workbench/browser/parts/notificat
2727
import { IListService, WorkbenchList } from 'vs/platform/list/browser/listService';
2828
import { NotificationFocusedContext } from 'vs/workbench/common/contextkeys';
2929
import { IAccessibleViewService, AccessibleViewService, IAccessibleContentProvider, IAccessibleViewOptions, AccessibleViewType, accessibleViewIsShown } from 'vs/workbench/contrib/accessibility/browser/accessibleView';
30+
import { IHoverService } from 'vs/workbench/services/hover/browser/hover';
3031

3132
registerAccessibilityConfiguration();
3233
registerSingleton(IAccessibleViewService, AccessibleViewService, InstantiationType.Delayed);
@@ -133,14 +134,18 @@ class HoverAccessibleViewContribution extends Disposable {
133134
const contextViewService = accessor.get(IContextViewService);
134135
const contextViewElement = contextViewService.getContextViewElement();
135136
const extensionHoverContent = contextViewElement?.textContent ?? undefined;
137+
const hoverService = accessor.get(IHoverService);
138+
136139
if (contextViewElement.classList.contains('accessible-view-container') || !extensionHoverContent) {
137140
// The accessible view, itself, uses the context view service to display the text. We don't want to read that.
138141
return false;
139142
}
140143
accessibleViewService.show({
141144
verbositySettingKey: AccessibilityVerbositySettingId.Hover,
142145
provideContent() { return extensionHoverContent; },
143-
onClose() { },
146+
onClose() {
147+
hoverService.showAndFocusLastHover();
148+
},
144149
options: this._options
145150
});
146151
return true;

src/vs/workbench/services/hover/browser/hover.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ export interface IHoverService {
3737
* "locked" via the alt/option key.
3838
*/
3939
hideHover(): void;
40+
41+
/**
42+
* This should only be used until we have the ability to show multiple context views
43+
* simultaneously. #188822
44+
*/
45+
showAndFocusLastHover(): void;
4046
}
4147

4248
export interface IHoverWidget extends IDisposable {

src/vs/workbench/services/hover/browser/hoverService.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class HoverService implements IHoverService {
2323

2424
private _currentHoverOptions: IHoverOptions | undefined;
2525
private _currentHover: HoverWidget | undefined;
26+
private _lastHoverOptions: IHoverOptions | undefined;
2627

2728
private _lastFocusedElementBeforeOpen: HTMLElement | undefined;
2829

@@ -40,6 +41,7 @@ export class HoverService implements IHoverService {
4041
return undefined;
4142
}
4243
this._currentHoverOptions = options;
44+
this._lastHoverOptions = options;
4345
if (options.trapFocus && document.activeElement) {
4446
this._lastFocusedElementBeforeOpen = document.activeElement as HTMLElement;
4547
} else {
@@ -108,6 +110,13 @@ export class HoverService implements IHoverService {
108110
}
109111
}
110112

113+
showAndFocusLastHover(): void {
114+
if (!this._lastHoverOptions) {
115+
return;
116+
}
117+
this.showHover(this._lastHoverOptions, true);
118+
}
119+
111120
private _keyDown(e: KeyboardEvent, hover: HoverWidget, hideOnKeyDown: boolean) {
112121
if (e.key === 'Alt') {
113122
hover.isLocked = true;

src/vs/workbench/test/browser/workbenchTestServices.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ class TestHoverService implements IHoverService {
749749
};
750750
return this.currentHover;
751751
}
752+
showAndFocusLastHover(): void { }
752753
hideHover(): void {
753754
this.currentHover?.dispose();
754755
}

0 commit comments

Comments
 (0)