Skip to content

Commit

Permalink
adding code in order to dispose the accessible hover view
Browse files Browse the repository at this point in the history
  • Loading branch information
aiday-mar committed May 21, 2024
1 parent fa6bc6c commit a0c67a5
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 63 deletions.
57 changes: 37 additions & 20 deletions src/vs/editor/contrib/hover/browser/hoverAccessibleViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { localize } from 'vs/nls';
import { format } from 'vs/base/common/strings';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { HoverController } from 'vs/editor/contrib/hover/browser/hoverController';
import { AccessibleViewType, AccessibleViewProviderId, AdvancedContentProvider, IAccessibleViewContentProvider, IAccessibleViewOptions, IAccessibleViewService } from 'vs/platform/accessibility/browser/accessibleView';
import { AccessibleViewType, AccessibleViewProviderId, AdvancedContentProvider, IAccessibleViewContentProvider, IAccessibleViewOptions } from 'vs/platform/accessibility/browser/accessibleView';
import { IAccessibleViewImplentation } from 'vs/platform/accessibility/browser/accessibleViewRegistry';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IHoverService } from 'vs/platform/hover/browser/hover';
Expand All @@ -19,7 +19,8 @@ import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService
import { Action, IAction } from 'vs/base/common/actions';
import { ThemeIcon } from 'vs/base/common/themables';
import { Codicon } from 'vs/base/common/codicons';
import { IDisposable } from 'vs/base/common/lifecycle';
import { Emitter, Event } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';

namespace HoverAccessibilityHelpNLS {
export const intro = localize('intro', "The hover widget is focused. Press the Tab key to cycle through the hover parts.");
Expand All @@ -37,32 +38,42 @@ export class HoverAccessibleView implements IAccessibleViewImplentation {
readonly name = 'hover';
readonly when = EditorContextKeys.hoverFocused;

private _provider: HoverAccessibilityHelpProvider | undefined;

getProvider(accessor: ServicesAccessor): AdvancedContentProvider | undefined {
const codeEditorService = accessor.get(ICodeEditorService);
const codeEditor = codeEditorService.getActiveCodeEditor() || codeEditorService.getFocusedCodeEditor();
if (!codeEditor) {
return undefined;
}
return accessor.get(IInstantiationService).createInstance(HoverAccessibilityHelpProvider, codeEditor);
this._provider = accessor.get(IInstantiationService).createInstance(HoverAccessibilityHelpProvider, codeEditor);
return this._provider;
}

dispose(): void {
this._provider?.dispose();
}
}

export class HoverAccessibilityHelpProvider implements IAccessibleViewContentProvider {
export class HoverAccessibilityHelpProvider extends Disposable implements IAccessibleViewContentProvider {

public readonly options: IAccessibleViewOptions;
public readonly id = AccessibleViewProviderId.Hover;
public readonly verbositySettingKey = 'accessibility.verbosity.hover';
public readonly actions: IAction[] = [];

private _onHoverContentsChanged: IDisposable | undefined;
private readonly _hoverController: HoverController | null = null;

private _onDidChangeContent: Emitter<void> = this._register(new Emitter<void>());
public onDidChangeContent: Event<void> = this._onDidChangeContent.event;

constructor(
private readonly _editor: ICodeEditor,
@IAccessibleViewService private readonly _accessibleViewService: IAccessibleViewService,
@IKeybindingService private readonly _keybindingService: IKeybindingService
) {
super();
this.options = {
language: this._editor.getModel()?.getLanguageId() ?? 'typescript',
language: this._editor.getModel()?.getLanguageId(),
type: AccessibleViewType.View
};
this.actions.push(new Action(INCREASE_HOVER_VERBOSITY_ACCESSIBLE_ACTION_ID, INCREASE_HOVER_VERBOSITY_ACTION_LABEL, ThemeIcon.asClassName(Codicon.add), true, () => {
Expand All @@ -71,38 +82,42 @@ export class HoverAccessibilityHelpProvider implements IAccessibleViewContentPro
this.actions.push(new Action(DECREASE_HOVER_VERBOSITY_ACCESSIBLE_ACTION_ID, DECREASE_HOVER_VERBOSITY_ACTION_LABEL, ThemeIcon.asClassName(Codicon.remove), true, () => {
this._editor.getAction(DECREASE_HOVER_VERBOSITY_ACTION_ID)?.run({ focus: false });
}));
this._hoverController = HoverController.get(this._editor);
if (this._hoverController) {
this._register(this._hoverController.onHoverContentsChanged(() => {
this._onDidChangeContent.fire();
}));
}
}

provideContent(): string {
const content: string[] = [];
content.push(HoverAccessibilityHelpNLS.intro);
const hoverController = HoverController.get(this._editor);
if (!hoverController) {
const content: string[] = [HoverAccessibilityHelpNLS.intro];
if (!this._hoverController) {
return content.join('\n');
}
const isFocusOnExpandableMarkdownHover = hoverController.isFocusOnMarkdownHoverWhichSupportsVerbosityAction(HoverVerbosityAction.Increase);
this._hoverController.shouldRemainOpenOnEditorMouseMoveOrLeave = true;
const isFocusOnExpandableMarkdownHover = this._hoverController.isFocusOnMarkdownHoverWhichSupportsVerbosityAction(HoverVerbosityAction.Increase);
if (isFocusOnExpandableMarkdownHover) {
content.push(this._descriptionForCommand(INCREASE_HOVER_VERBOSITY_ACTION_ID, HoverAccessibilityHelpNLS.increaseVerbosity, HoverAccessibilityHelpNLS.increaseVerbosityNoKb));
}
const isFocusOnContractableMarkdownHover = hoverController.isFocusOnMarkdownHoverWhichSupportsVerbosityAction(HoverVerbosityAction.Decrease);
const isFocusOnContractableMarkdownHover = this._hoverController.isFocusOnMarkdownHoverWhichSupportsVerbosityAction(HoverVerbosityAction.Decrease);
if (isFocusOnContractableMarkdownHover) {
content.push(this._descriptionForCommand(DECREASE_HOVER_VERBOSITY_ACTION_ID, HoverAccessibilityHelpNLS.decreaseVerbosity, HoverAccessibilityHelpNLS.decreaseVerbosityNoKb));
}
const hoverContent = hoverController.lastFocusedMarkdownHoverContent();
const hoverContent = this._hoverController.lastFocusedMarkdownHoverContent();
if (hoverContent) {
content.push('\n' + HoverAccessibilityHelpNLS.hoverContent);
content.push('\n' + hoverContent);
}
this._onHoverContentsChanged?.dispose();
this._onHoverContentsChanged = hoverController.onHoverContentsChanged(() => {
this._accessibleViewService.rerender();
});
return content.join('\n');
}

onClose(): void {
HoverController.get(this._editor)?.focus();
this._onHoverContentsChanged?.dispose();
if (!this._hoverController) {
return;
}
this._hoverController.focus();
this._hoverController.shouldRemainOpenOnEditorMouseMoveOrLeave = false;
}

private _descriptionForCommand(commandId: string, msg: string, noKbMsg: string): string {
Expand Down Expand Up @@ -140,4 +155,6 @@ export class ExtHoverAccessibleView implements IAccessibleViewImplentation {
options: { language: 'typescript', type: AccessibleViewType.View }
};
}

dispose() { }
}
16 changes: 4 additions & 12 deletions src/vs/editor/contrib/hover/browser/hoverController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { ContentHoverWidget } from 'vs/editor/contrib/hover/browser/contentHover
import { ContentHoverController } from 'vs/editor/contrib/hover/browser/contentHoverController';
import 'vs/css!./hover';
import { MarginHoverWidget } from 'vs/editor/contrib/hover/browser/marginHoverWidget';
import { AccessibleViewProviderId, IAccessibleViewService } from 'vs/platform/accessibility/browser/accessibleView';
import { Emitter } from 'vs/base/common/event';

// sticky hover widget which doesn't disappear on focus out and such
Expand Down Expand Up @@ -55,6 +54,7 @@ export class HoverController extends Disposable implements IEditorContribution {

// Other fields
public static readonly ID = 'editor.contrib.hover';
public shouldRemainOpenOnEditorMouseMoveOrLeave: boolean = false;

private readonly _listenersStore = new DisposableStore();

Expand All @@ -73,8 +73,7 @@ export class HoverController extends Disposable implements IEditorContribution {
constructor(
private readonly _editor: ICodeEditor,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IKeybindingService private readonly _keybindingService: IKeybindingService,
@IAccessibleViewService private readonly _accessibleViewService: IAccessibleViewService,
@IKeybindingService private readonly _keybindingService: IKeybindingService
) {
super();
this._reactToEditorMouseMoveRunner = this._register(
Expand Down Expand Up @@ -182,7 +181,7 @@ export class HoverController extends Disposable implements IEditorContribution {
}

private _onEditorMouseLeave(mouseEvent: IPartialEditorMouseEvent): void {
if (this._isHoverAccessibleViewVisible) {
if (this.shouldRemainOpenOnEditorMouseMoveOrLeave) {
return;
}

Expand Down Expand Up @@ -234,7 +233,7 @@ export class HoverController extends Disposable implements IEditorContribution {
}

private _onEditorMouseMove(mouseEvent: IEditorMouseEvent): void {
if (this._isHoverAccessibleViewVisible) {
if (this.shouldRemainOpenOnEditorMouseMoveOrLeave) {
return;
}

Expand Down Expand Up @@ -270,13 +269,6 @@ export class HoverController extends Disposable implements IEditorContribution {
this._reactToEditorMouseMove(mouseEvent);
}

private get _isHoverAccessibleViewVisible(): boolean {
const isAccessibleViewVisible = this._accessibleViewService.isVisible();
const isHoverProviderUsed = this._accessibleViewService.providerId() === AccessibleViewProviderId.Hover;
const isHoverAccessibleViewVisible = isAccessibleViewVisible && isHoverProviderUsed;
return isHoverAccessibleViewVisible;
}

private _reactToEditorMouseMove(mouseEvent: IEditorMouseEvent | undefined): void {

if (!mouseEvent) {
Expand Down
6 changes: 3 additions & 3 deletions src/vs/platform/accessibility/browser/accessibleView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ export interface IAccessibleViewService {
show(provider: AccesibleViewContentProvider, position?: IPosition): void;
showLastProvider(id: AccessibleViewProviderId): void;
showAccessibleViewHelp(): void;
rerender(): void;
isVisible(): boolean;
providerId(): string;
next(): void;
previous(): void;
navigateToCodeBlock(type: 'next' | 'previous'): void;
Expand Down Expand Up @@ -139,6 +136,7 @@ export class AdvancedContentProvider implements IAccessibleViewContentProvider {
public actions?: IAction[],
public next?: () => void,
public previous?: () => void,
public onDidChangeContent?: Event<void>,
public onKeyDown?: (e: IKeyboardEvent) => void,
public getSymbols?: () => IAccessibleViewSymbol[],
public onDidRequestClearLastProvider?: Event<AccessibleViewProviderId>,
Expand All @@ -155,6 +153,7 @@ export class ExtensionContentProvider implements IBasicContentProvider {
public next?: () => void,
public previous?: () => void,
public actions?: IAction[],
public onDidChangeContent?: Event<void>,
) { }
}

Expand All @@ -166,4 +165,5 @@ export interface IBasicContentProvider {
actions?: IAction[];
previous?(): void;
next?(): void;
onDidChangeContent?: Event<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AccessibleViewType, AdvancedContentProvider, ExtensionContentProvider }
import { ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';

export interface IAccessibleViewImplentation {
export interface IAccessibleViewImplentation extends IDisposable {
type: AccessibleViewType;
priority: number;
name: string;
Expand All @@ -30,6 +30,7 @@ export const AccessibleViewRegistry = new class AccessibleViewRegistry {
if (idx !== -1) {
this._implementations.splice(idx, 1);
}
implementation.dispose();
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export class NotificationAccessibleView implements IAccessibleViewImplentation {
}
return getProvider();
}
dispose() { }
}


Expand Down
33 changes: 7 additions & 26 deletions src/vs/workbench/contrib/accessibility/browser/accessibleView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export class AccessibleView extends Disposable {
private readonly _toolbar: WorkbenchToolBar;

private _currentProvider: AccesibleViewContentProvider | undefined;
private _currentContainer: HTMLElement | undefined;
private _currentContent: string | undefined;

private _lastProvider: AccesibleViewContentProvider | undefined;
Expand Down Expand Up @@ -244,11 +243,12 @@ export class AccessibleView extends Disposable {
if (!provider) {
return;
}
let viewContainer: HTMLElement | undefined;
const delegate: IContextViewDelegate = {
getAnchor: () => { return { x: (getActiveWindow().innerWidth / 2) - ((Math.min(this._layoutService.activeContainerDimension.width * 0.62 /* golden cut */, DIMENSIONS.MAX_WIDTH)) / 2), y: this._layoutService.activeContainerOffset.quickPickTop }; },
render: (container) => {
this._currentContainer = container;
this._currentContainer.classList.add('accessible-view-container');
viewContainer = container;
viewContainer.classList.add('accessible-view-container');
return this._render(provider, container, showAccessibleViewHelp);
},
onHide: () => {
Expand Down Expand Up @@ -289,21 +289,10 @@ export class AccessibleView extends Disposable {
if (provider instanceof ExtensionContentProvider) {
this._storageService.store(`${ACCESSIBLE_VIEW_SHOWN_STORAGE_PREFIX}${provider.id}`, true, StorageScope.APPLICATION, StorageTarget.USER);
}
}

rerender(): void {
if (!this._currentProvider || !this._currentContainer) {
return;
}
this._render(this._currentProvider, this._currentContainer, false);
}

isVisible(): boolean {
return this._accessibleViewIsShown.get() ?? false;
}
provider.onDidChangeContent?.(() => {
if (viewContainer) { this._render(provider, viewContainer, showAccessibleViewHelp); }
});

providerId(): string {
return this._accessibleViewCurrentProviderId.get() ?? '';
}

previous(): void {
Expand Down Expand Up @@ -624,6 +613,7 @@ export class AccessibleView extends Disposable {
provider.actions,
provider.next,
provider.previous,
provider.onDidChangeContent,
provider.onKeyDown,
provider.getSymbols,
) : new ExtensionContentProvider(
Expand Down Expand Up @@ -770,15 +760,6 @@ export class AccessibleViewService extends Disposable implements IAccessibleView
showLastProvider(id: AccessibleViewProviderId): void {
this._accessibleView?.showLastProvider(id);
}
rerender(): void {
this._accessibleView?.rerender();
}
isVisible(): boolean {
return this._accessibleView?.isVisible() ?? false;
}
providerId(): string {
return this._accessibleView?.providerId() ?? '';
}
next(): void {
this._accessibleView?.next();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ function registerAccessibilityHelpAction(keybindingService: IKeybindingService,
() => helpContent.value,
() => viewsService.openView(viewDescriptor.id, true)
);
}
},
dispose: () => { },
}));

disposableStore.add(keybindingService.onDidUpdateKeybindings(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class ChatAccessibilityHelp implements IAccessibleViewImplentation {
const codeEditor = accessor.get(ICodeEditorService).getActiveCodeEditor() || accessor.get(ICodeEditorService).getFocusedCodeEditor();
return getChatAccessibilityHelpProvider(accessor, codeEditor ?? undefined, 'panelChat');
}
dispose() { }
}

export function getAccessibilityHelpText(accessor: ServicesAccessor, type: 'panelChat' | 'inlineChat'): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,5 @@ export class ChatResponseAccessibleView implements IAccessibleViewImplentation {
};
}
}
dispose() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ export class DiffEditorAccessibilityHelp implements IAccessibleViewImplentation
options: { type: AccessibleViewType.Help }
};
}
dispose() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ export class CommentsAccessibilityHelp implements IAccessibleViewImplentation {
getProvider(accessor: ServicesAccessor) {
return accessor.get(IInstantiationService).createInstance(CommentsAccessibilityHelpProvider);
}
dispose() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export class InlineChatAccessibilityHelp implements IAccessibleViewImplentation
}
return getChatAccessibilityHelpProvider(accessor, codeEditor, 'inlineChat');
}
dispose() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ export class InlineChatAccessibleView implements IAccessibleViewImplentation {
options: { type: AccessibleViewType.View }
};
}
dispose() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class NotebookAccessibilityHelp implements IAccessibleViewImplentation {
}
return;
}
dispose() { }
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class NotebookAccessibleView implements IAccessibleViewImplentation {
const editorService = accessor.get(IEditorService);
return showAccessibleOutput(editorService);
}
dispose() { }
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class TerminalChatAccessibilityHelp implements IAccessibleViewImplentatio
options: { type: AccessibleViewType.Help }
};
}
dispose() { }
}

export function getAccessibilityHelpText(accessor: ServicesAccessor): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ export class TerminalInlineChatAccessibleView implements IAccessibleViewImplenta
options: { type: AccessibleViewType.View }
};
}
dispose() { }
}

0 comments on commit a0c67a5

Please sign in to comment.