Skip to content

Commit 979ad0a

Browse files
authored
Set focus back to the editor hover part on escape from the accessible view/help (microsoft#218274)
adding code in order to focus back a specific hover part on escaping from the accessible view/help
1 parent 44623fa commit 979ad0a

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ export class ContentHoverController extends Disposable implements IHoverWidget {
321321
this._contentHoverWidget.focus();
322322
}
323323

324+
public focusHoverPartWithIndex(index: number): void {
325+
this._renderedContentHover?.focusHoverPartWithIndex(index);
326+
}
327+
324328
public scrollUp(): void {
325329
this._contentHoverWidget.scrollUp();
326330
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export class RenderedContentHover extends Disposable {
7777
return this._renderedHoverParts.focusedHoverPartIndex;
7878
}
7979

80+
public focusHoverPartWithIndex(index: number): void {
81+
this._renderedHoverParts.focusHoverPartWithIndex(index);
82+
}
83+
8084
public getAccessibleWidgetContent(): string {
8185
return this._renderedHoverParts.getAccessibleContent();
8286
}
@@ -328,6 +332,13 @@ class RenderedContentHoverParts extends Disposable {
328332
this._colorHoverParticipant = participants.find(p => p instanceof ColorHoverParticipant);
329333
}
330334

335+
public focusHoverPartWithIndex(index: number): void {
336+
if (index < 0 || index >= this._renderedParts.length) {
337+
return;
338+
}
339+
this._renderedParts[index].hoverElement.focus();
340+
}
341+
331342
public getAccessibleContent(): string {
332343
const content: string[] = [];
333344
for (let i = 0; i < this._renderedParts.length; i++) {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,12 @@ abstract class BaseHoverAccessibleViewProvider extends Disposable implements IAc
117117
if (!this._hoverController) {
118118
return;
119119
}
120+
if (this._focusedHoverPartIndex === -1) {
121+
this._hoverController.focus();
122+
} else {
123+
this._hoverController.focusHoverPartWithIndex(this._focusedHoverPartIndex);
124+
}
120125
this._focusedHoverPartIndex = -1;
121-
this._hoverController.focus();
122126
this._hoverController.shouldKeepOpenOnEditorMouseMoveOrLeave = false;
123127
this.dispose();
124128
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,10 @@ export class HoverController extends Disposable implements IEditorContribution {
433433
this._contentWidget?.focus();
434434
}
435435

436+
public focusHoverPartWithIndex(index: number): void {
437+
this._contentWidget?.focusHoverPartWithIndex(index);
438+
}
439+
436440
public scrollUp(): void {
437441
this._contentWidget?.scrollUp();
438442
}

0 commit comments

Comments
 (0)