Only enable next/previous actions when there are multiple suggestions. Fixes #125296.

This commit is contained in:
Henning Dieterichs
2021-06-04 18:02:54 +02:00
parent 1b15230de9
commit 7cd9352928
8 changed files with 95 additions and 26 deletions

View File

@@ -143,3 +143,9 @@
-webkit-user-select: none;
user-select: none;
}
.monaco-hover-content .action-container.disabled {
pointer-events: none;
opacity: 0.4;
cursor: default;
}

View File

@@ -5,7 +5,7 @@
import 'vs/css!./hover';
import * as dom from 'vs/base/browser/dom';
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
import { Disposable } from 'vs/base/common/lifecycle';
import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement';
const $ = dom.$;
@@ -42,19 +42,43 @@ export class HoverWidget extends Disposable {
}
}
export function renderHoverAction(parent: HTMLElement, actionOptions: { label: string, iconClass?: string, run: (target: HTMLElement) => void, commandId: string }, keybindingLabel: string | null): IDisposable {
const actionContainer = dom.append(parent, $('div.action-container'));
const action = dom.append(actionContainer, $('a.action'));
action.setAttribute('href', '#');
action.setAttribute('role', 'button');
if (actionOptions.iconClass) {
dom.append(action, $(`span.icon.${actionOptions.iconClass}`));
export class HoverAction extends Disposable {
public static render(parent: HTMLElement, actionOptions: { label: string, iconClass?: string, run: (target: HTMLElement) => void, commandId: string }, keybindingLabel: string | null) {
return new HoverAction(parent, actionOptions, keybindingLabel);
}
private readonly actionContainer: HTMLElement;
private readonly action: HTMLElement;
private constructor(parent: HTMLElement, actionOptions: { label: string, iconClass?: string, run: (target: HTMLElement) => void, commandId: string }, keybindingLabel: string | null) {
super();
this.actionContainer = dom.append(parent, $('div.action-container'));
this.action = dom.append(this.actionContainer, $('a.action'));
this.action.setAttribute('href', '#');
this.action.setAttribute('role', 'button');
if (actionOptions.iconClass) {
dom.append(this.action, $(`span.icon.${actionOptions.iconClass}`));
}
const label = dom.append(this.action, $('span'));
label.textContent = keybindingLabel ? `${actionOptions.label} (${keybindingLabel})` : actionOptions.label;
this._register(dom.addDisposableListener(this.actionContainer, dom.EventType.CLICK, e => {
e.stopPropagation();
e.preventDefault();
actionOptions.run(this.actionContainer);
}));
this.setEnabled(true);
}
public setEnabled(enabled: boolean): void {
if (enabled) {
this.actionContainer.classList.remove('disabled');
this.actionContainer.removeAttribute('aria-disabled');
} else {
this.actionContainer.classList.add('disabled');
this.actionContainer.setAttribute('aria-disabled', 'true');
}
}
const label = dom.append(action, $('span'));
label.textContent = keybindingLabel ? `${actionOptions.label} (${keybindingLabel})` : actionOptions.label;
return dom.addDisposableListener(actionContainer, dom.EventType.CLICK, e => {
e.stopPropagation();
e.preventDefault();
actionOptions.run(actionContainer);
});
}