Skip to content

Commit

Permalink
Set focus back to the editor hover part on escape from the accessible…
Browse files Browse the repository at this point in the history
… view/help (microsoft#218274)

adding code in order to focus back a specific hover part on escaping from the accessible view/help
  • Loading branch information
aiday-mar authored Jun 26, 2024
1 parent 44623fa commit 979ad0a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/vs/editor/contrib/hover/browser/contentHoverController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ export class ContentHoverController extends Disposable implements IHoverWidget {
this._contentHoverWidget.focus();
}

public focusHoverPartWithIndex(index: number): void {
this._renderedContentHover?.focusHoverPartWithIndex(index);
}

public scrollUp(): void {
this._contentHoverWidget.scrollUp();
}
Expand Down
11 changes: 11 additions & 0 deletions src/vs/editor/contrib/hover/browser/contentHoverRendered.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export class RenderedContentHover extends Disposable {
return this._renderedHoverParts.focusedHoverPartIndex;
}

public focusHoverPartWithIndex(index: number): void {
this._renderedHoverParts.focusHoverPartWithIndex(index);
}

public getAccessibleWidgetContent(): string {
return this._renderedHoverParts.getAccessibleContent();
}
Expand Down Expand Up @@ -328,6 +332,13 @@ class RenderedContentHoverParts extends Disposable {
this._colorHoverParticipant = participants.find(p => p instanceof ColorHoverParticipant);
}

public focusHoverPartWithIndex(index: number): void {
if (index < 0 || index >= this._renderedParts.length) {
return;
}
this._renderedParts[index].hoverElement.focus();
}

public getAccessibleContent(): string {
const content: string[] = [];
for (let i = 0; i < this._renderedParts.length; i++) {
Expand Down
6 changes: 5 additions & 1 deletion src/vs/editor/contrib/hover/browser/hoverAccessibleViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ abstract class BaseHoverAccessibleViewProvider extends Disposable implements IAc
if (!this._hoverController) {
return;
}
if (this._focusedHoverPartIndex === -1) {
this._hoverController.focus();
} else {
this._hoverController.focusHoverPartWithIndex(this._focusedHoverPartIndex);
}
this._focusedHoverPartIndex = -1;
this._hoverController.focus();
this._hoverController.shouldKeepOpenOnEditorMouseMoveOrLeave = false;
this.dispose();
}
Expand Down
4 changes: 4 additions & 0 deletions src/vs/editor/contrib/hover/browser/hoverController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ export class HoverController extends Disposable implements IEditorContribution {
this._contentWidget?.focus();
}

public focusHoverPartWithIndex(index: number): void {
this._contentWidget?.focusHoverPartWithIndex(index);
}

public scrollUp(): void {
this._contentWidget?.scrollUp();
}
Expand Down

0 comments on commit 979ad0a

Please sign in to comment.