Skip to content

Commit 4148d30

Browse files
committed
1 parent 5f8e69f commit 4148d30

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

src/vs/editor/contrib/hover/browser/contentHover.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
2424
import { Context as SuggestContext } from 'vs/editor/contrib/suggest/browser/suggest';
2525
import { AsyncIterableObject } from 'vs/base/common/async';
2626
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
27+
import { withNullAsUndefined } from 'vs/base/common/types';
2728

2829
const $ = dom.$;
2930

3031
export class ContentHoverController extends Disposable {
3132

3233
private readonly _participants: IEditorHoverParticipant[];
34+
3335
private readonly _widget = this._register(this._instantiationService.createInstance(ContentHoverWidget, this._editor));
36+
37+
getWidgetContents(): string | undefined { return withNullAsUndefined(this._widget.getDomNode()?.textContent); }
38+
3439
private readonly _computer: ContentHoverComputer;
3540
private readonly _hoverOperation: HoverOperation<IHoverPart>;
3641

src/vs/editor/contrib/hover/browser/hover.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export class ModesHoverController implements IEditorContribution {
4040
private readonly _didChangeConfigurationHandler: IDisposable;
4141

4242
private _contentWidget: ContentHoverController | null;
43+
44+
getWidgetContents(): string | undefined { return this._contentWidget?.getWidgetContents(); }
45+
4346
private _glyphWidget: MarginHoverWidget | null;
4447

4548
private _isMouseDown: boolean;
@@ -48,6 +51,7 @@ export class ModesHoverController implements IEditorContribution {
4851
private _isHoverSticky!: boolean;
4952
private _hoverActivatedByColorDecoratorClick: boolean = false;
5053

54+
5155
static get(editor: ICodeEditor): ModesHoverController | null {
5256
return editor.getContribution<ModesHoverController>(ModesHoverController.ID);
5357
}

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { localize } from 'vs/nls';
1313
import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
1414
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
1515
import { IKeybindingService, IKeyboardEvent } from 'vs/platform/keybinding/common/keybinding';
16-
import { AccessibilityHelpAction, registerAccessibilityConfiguration } from 'vs/workbench/contrib/accessibility/browser/accessibilityContribution';
16+
import { AccessibilityHelpAction, AccessibilityViewAction, registerAccessibilityConfiguration } from 'vs/workbench/contrib/accessibility/browser/accessibilityContribution';
1717
import { AccessibleViewService, IAccessibleContentProvider, IAccessibleViewOptions, IAccessibleViewService } from 'vs/workbench/contrib/accessibility/browser/accessibleView';
1818
import * as strings from 'vs/base/common/strings';
1919
import * as platform from 'vs/base/common/platform';
@@ -26,6 +26,8 @@ import { NEW_UNTITLED_FILE_COMMAND_ID } from 'vs/workbench/contrib/files/browser
2626
import { KeyCode } from 'vs/base/common/keyCodes';
2727
import { URI } from 'vs/base/common/uri';
2828
import { IOpenerService } from 'vs/platform/opener/common/opener';
29+
import { ModesHoverController } from 'vs/editor/contrib/hover/browser/hover';
30+
import { withNullAsUndefined } from 'vs/base/common/types';
2931

3032
registerAccessibilityConfiguration();
3133
registerSingleton(IAccessibleViewService, AccessibleViewService, InstantiationType.Delayed);
@@ -134,3 +136,44 @@ const workbenchRegistry = Registry.as<IWorkbenchContributionsRegistry>(Workbench
134136
workbenchRegistry.registerWorkbenchContribution(EditorAccessibilityHelpContribution, LifecyclePhase.Eventually);
135137

136138

139+
140+
class HoverAccessibileViewContribution extends Disposable {
141+
static ID: 'hoverAccessibleViewContribution';
142+
constructor() {
143+
super();
144+
this._register(AccessibilityViewAction.addImplementation(105, 'hover', accessor => {
145+
const accessibleViewService = accessor.get(IAccessibleViewService);
146+
const codeEditorService = accessor.get(ICodeEditorService);
147+
const editor = codeEditorService.getActiveCodeEditor() || codeEditorService.getFocusedCodeEditor();
148+
if (!editor) {
149+
return false;
150+
}
151+
const controller = ModesHoverController.get(editor);
152+
const hoverContent = withNullAsUndefined(controller?.getWidgetContents());
153+
if (!controller || !hoverContent) {
154+
return false;
155+
}
156+
function provideContent(): string {
157+
return hoverContent!;
158+
}
159+
const provider = accessibleViewService.registerProvider({
160+
id: 'hover',
161+
provideContent,
162+
onClose() {
163+
provider.dispose();
164+
controller.focus();
165+
},
166+
onKeyDown(e: IKeyboardEvent) {
167+
168+
},
169+
options: { ariaLabel: localize('hoverAccessibleView', "Hover Accessible View") }
170+
});
171+
accessibleViewService.show('hover');
172+
return true;
173+
}));
174+
}
175+
}
176+
177+
const workbenchContributionsRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
178+
workbenchContributionsRegistry.registerWorkbenchContribution(HoverAccessibileViewContribution, LifecyclePhase.Eventually);
179+

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import { SelectionClipboardContributionID } from 'vs/workbench/contrib/codeEdito
2121
import { getSimpleEditorOptions } from 'vs/workbench/contrib/codeEditor/browser/simpleEditorOptions';
2222
import { IDisposable } from 'xterm';
2323

24+
const enum DIMENSION_DEFAULT {
25+
WIDTH = .4,
26+
HEIGHT = .2
27+
}
2428

2529
export interface IAccessibleContentProvider {
2630
id: string;
@@ -92,7 +96,7 @@ class AccessibleView extends Disposable {
9296

9397
private _render(provider: IAccessibleContentProvider, container: HTMLElement): IDisposable {
9498

95-
const fragment = localize('exit-tip', 'Exit this menu via the Escape key.\n') + provider.provideContent();
99+
const fragment = provider.provideContent() + localize('exit-tip', 'Exit this menu via the Escape key.\n');
96100

97101
this._getTextModel(URI.from({ path: `accessible-view-${provider.id}`, scheme: 'accessible-view', fragment })).then((model) => {
98102
if (!model) {
@@ -124,8 +128,8 @@ class AccessibleView extends Disposable {
124128
const windowWidth = window.innerWidth;
125129
const windowHeight = window.innerHeight;
126130

127-
const width = windowWidth * .4;
128-
const height = Math.min(.4 * windowHeight, this._editorWidget.getContentHeight());
131+
const width = windowWidth * DIMENSION_DEFAULT.WIDTH;
132+
const height = Math.min(windowHeight * DIMENSION_DEFAULT.HEIGHT, this._editorWidget.getContentHeight());
129133
this._editorWidget.layout({ width, height });
130134
const top = Math.round((windowHeight - height) / 2);
131135
this._editorContainer.style.top = `${top}px`;

0 commit comments

Comments
 (0)