Skip to content

Commit a141eda

Browse files
authored
Reusing NLS label of markdown verbose hover in accessible view (microsoft#213680)
* reusing nls label * polishing
1 parent 3cc0f30 commit a141eda

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ import { IContextViewService } from 'vs/platform/contextview/browser/contextView
1111
import { IHoverService } from 'vs/platform/hover/browser/hover';
1212
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
1313
import { HoverVerbosityAction } from 'vs/editor/common/languages';
14-
import { DECREASE_HOVER_VERBOSITY_ACCESSIBLE_ACTION_ID, DECREASE_HOVER_VERBOSITY_ACTION_ID, DECREASE_HOVER_VERBOSITY_ACTION_LABEL, INCREASE_HOVER_VERBOSITY_ACCESSIBLE_ACTION_ID, INCREASE_HOVER_VERBOSITY_ACTION_ID, INCREASE_HOVER_VERBOSITY_ACTION_LABEL } from 'vs/editor/contrib/hover/browser/hoverActionIds';
14+
import { DECREASE_HOVER_VERBOSITY_ACCESSIBLE_ACTION_ID, DECREASE_HOVER_VERBOSITY_ACTION_ID, INCREASE_HOVER_VERBOSITY_ACCESSIBLE_ACTION_ID, INCREASE_HOVER_VERBOSITY_ACTION_ID } from 'vs/editor/contrib/hover/browser/hoverActionIds';
1515
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
1616
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
1717
import { Action, IAction } from 'vs/base/common/actions';
1818
import { ThemeIcon } from 'vs/base/common/themables';
1919
import { Codicon } from 'vs/base/common/codicons';
2020
import { Emitter, Event } from 'vs/base/common/event';
2121
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
22+
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
23+
import { labelForHoverVerbosityAction } from 'vs/editor/contrib/hover/browser/markdownHoverParticipant';
2224

2325
namespace HoverAccessibilityHelpNLS {
2426
export const intro = localize('intro', "Focus on the hover widget to cycle through the hover parts with the Tab key.");
@@ -46,7 +48,8 @@ export class HoverAccessibleView implements IAccessibleViewImplentation {
4648
if (!hoverController) {
4749
return;
4850
}
49-
this._provider = accessor.get(IInstantiationService).createInstance(HoverAccessibleViewProvider, codeEditor, hoverController);
51+
const keybindingService = accessor.get(IKeybindingService);
52+
this._provider = accessor.get(IInstantiationService).createInstance(HoverAccessibleViewProvider, keybindingService, codeEditor, hoverController);
5053
return this._provider;
5154
}
5255

@@ -125,7 +128,6 @@ abstract class BaseHoverAccessibleViewProvider extends Disposable implements IAc
125128
}
126129
}
127130

128-
129131
export class HoverAccessibilityHelpProvider extends BaseHoverAccessibleViewProvider implements IAccessibleViewContentProvider {
130132

131133
public readonly options: IAccessibleViewOptions = { type: AccessibleViewType.Help };
@@ -190,6 +192,7 @@ export class HoverAccessibleViewProvider extends BaseHoverAccessibleViewProvider
190192
public readonly options: IAccessibleViewOptions = { type: AccessibleViewType.View };
191193

192194
constructor(
195+
private readonly _keybindingService: IKeybindingService,
193196
private readonly _editor: ICodeEditor,
194197
hoverController: HoverController,
195198
) {
@@ -212,22 +215,20 @@ export class HoverAccessibleViewProvider extends BaseHoverAccessibleViewProvider
212215
private _getActionFor(editor: ICodeEditor, action: HoverVerbosityAction): IAction {
213216
let actionId: string;
214217
let accessibleActionId: string;
215-
let actionLabel: string;
216218
let actionCodicon: ThemeIcon;
217219
switch (action) {
218220
case HoverVerbosityAction.Increase:
219221
actionId = INCREASE_HOVER_VERBOSITY_ACTION_ID;
220222
accessibleActionId = INCREASE_HOVER_VERBOSITY_ACCESSIBLE_ACTION_ID;
221-
actionLabel = INCREASE_HOVER_VERBOSITY_ACTION_LABEL;
222223
actionCodicon = Codicon.add;
223224
break;
224225
case HoverVerbosityAction.Decrease:
225226
actionId = DECREASE_HOVER_VERBOSITY_ACTION_ID;
226227
accessibleActionId = DECREASE_HOVER_VERBOSITY_ACCESSIBLE_ACTION_ID;
227-
actionLabel = DECREASE_HOVER_VERBOSITY_ACTION_LABEL;
228228
actionCodicon = Codicon.remove;
229229
break;
230230
}
231+
const actionLabel = labelForHoverVerbosityAction(this._keybindingService, action);
231232
const actionEnabled = this._hoverController.doesMarkdownHoverAtIndexSupportVerbosityAction(this._markdownHoverFocusedIndex, action);
232233
return new Action(accessibleActionId, actionLabel, ThemeIcon.asClassName(actionCodicon), actionEnabled, () => {
233234
editor.getAction(actionId)?.run({ index: this._markdownHoverFocusedIndex, focus: false });

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -324,17 +324,7 @@ class MarkdownRenderedHoverParts extends Disposable {
324324
const actionElement = dom.append(container, $(ThemeIcon.asCSSSelector(isActionIncrease ? increaseHoverVerbosityIcon : decreaseHoverVerbosityIcon)));
325325
actionElement.tabIndex = 0;
326326
const hoverDelegate = new WorkbenchHoverDelegate('mouse', false, { target: container, position: { hoverPosition: HoverPosition.LEFT } }, this._configurationService, this._hoverService);
327-
if (isActionIncrease) {
328-
const kb = this._keybindingService.lookupKeybinding(INCREASE_HOVER_VERBOSITY_ACTION_ID);
329-
store.add(this._hoverService.setupUpdatableHover(hoverDelegate, actionElement, kb ?
330-
nls.localize('increaseVerbosityWithKb', "Increase Verbosity ({0})", kb.getLabel()) :
331-
nls.localize('increaseVerbosity', "Increase Verbosity")));
332-
} else {
333-
const kb = this._keybindingService.lookupKeybinding(DECREASE_HOVER_VERBOSITY_ACTION_ID);
334-
store.add(this._hoverService.setupUpdatableHover(hoverDelegate, actionElement, kb ?
335-
nls.localize('decreaseVerbosityWithKb', "Decrease Verbosity ({0})", kb.getLabel()) :
336-
nls.localize('decreaseVerbosity', "Decrease Verbosity")));
337-
}
327+
store.add(this._hoverService.setupUpdatableHover(hoverDelegate, actionElement, labelForHoverVerbosityAction(this._keybindingService, action)));
338328
if (!actionEnabled) {
339329
actionElement.classList.add('disabled');
340330
return store;
@@ -485,3 +475,20 @@ function renderMarkdownInContainer(
485475
}
486476
return store;
487477
}
478+
479+
export function labelForHoverVerbosityAction(keybindingService: IKeybindingService, action: HoverVerbosityAction): string {
480+
switch (action) {
481+
case HoverVerbosityAction.Increase: {
482+
const kb = keybindingService.lookupKeybinding(INCREASE_HOVER_VERBOSITY_ACTION_ID);
483+
return kb ?
484+
nls.localize('increaseVerbosityWithKb', "Increase Hover Verbosity ({0})", kb.getLabel()) :
485+
nls.localize('increaseVerbosity', "Increase Hover Verbosity");
486+
}
487+
case HoverVerbosityAction.Decrease: {
488+
const kb = keybindingService.lookupKeybinding(DECREASE_HOVER_VERBOSITY_ACTION_ID);
489+
return kb ?
490+
nls.localize('decreaseVerbosityWithKb', "Decrease Hover Verbosity ({0})", kb.getLabel()) :
491+
nls.localize('decreaseVerbosity', "Decrease Hover Verbosity");
492+
}
493+
}
494+
}

0 commit comments

Comments
 (0)