提交 cb1c7be2 编写于 作者: B Benjamin Pasero

quick access - align more with current solution

上级 7d4cd4a3
......@@ -354,7 +354,7 @@ export class SelectBoxList extends Disposable implements ISelectBoxDelegate, ILi
content.push(`.monaco-select-box-dropdown-container > .select-box-dropdown-list-container .monaco-list .monaco-list-row.option-disabled:hover { background-color: ${this.styles.selectBackground} !important; }`);
}
// Match quickOpen outline styles - ignore for disabled options
// Match quick input outline styles - ignore for disabled options
if (this.styles.listFocusOutline) {
content.push(`.monaco-select-box-dropdown-container > .select-box-dropdown-list-container .monaco-list .monaco-list-row.focused { outline: 1.6px dotted ${this.styles.listFocusOutline} !important; outline-offset: -1.6px !important; }`);
}
......
......@@ -391,6 +391,7 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
private _matchOnLabel = true;
private _sortByLabel = true;
private _autoFocusOnList = true;
private _autoFocusSecondEntry = false;
private _activeItems: T[] = [];
private activeItemsUpdated = false;
private activeItemsToConfirm: T[] | null = [];
......@@ -520,7 +521,6 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
this.update();
}
get autoFocusOnList() {
return this._autoFocusOnList;
}
......@@ -530,6 +530,14 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
this.update();
}
get autoFocusSecondEntry() {
return this._autoFocusSecondEntry;
}
set autoFocusSecondEntry(autoFocusSecondEntry: boolean) {
this._autoFocusSecondEntry = autoFocusSecondEntry;
}
get activeItems() {
return this._activeItems;
}
......@@ -851,10 +859,9 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
this.ui.checkAll.checked = this.ui.list.getAllVisibleChecked();
this.ui.visibleCount.setCount(this.ui.list.getVisibleCount());
this.ui.count.setCount(this.ui.list.getCheckedCount());
if (isQuickNavigating && previousItemCount === 0) {
// quick navigate: automatically focus the second entry
// so that upon release the item is picked directly
if (this._autoFocusSecondEntry && previousItemCount === 0) {
this.ui.list.focus(QuickInputListFocus.Second);
this._autoFocusSecondEntry = false;
} else {
this.trySelectFirst();
}
......
......@@ -237,6 +237,14 @@ export interface IQuickPick<T extends IQuickPickItem> extends IQuickInput {
autoFocusOnList: boolean;
/**
* If enabled, will try to select the second entry of the picks
* once they appear instead of the first one. This is useful
* e.g. when `quickNavigate` is enabled to be able to select
* a previous entry by just releasing the quick nav keys.
*/
autoFocusSecondEntry: boolean;
quickNavigate: IQuickNavigateConfiguration | undefined;
activeItems: ReadonlyArray<T>;
......
......@@ -178,7 +178,7 @@ interface ICommandsQuickAccessConfiguration {
};
}
class CommandsHistory extends Disposable {
export class CommandsHistory extends Disposable {
static readonly DEFAULT_COMMANDS_HISTORY_LENGTH = 50;
......
......@@ -40,6 +40,7 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon
picker.placeholder = descriptor?.placeholder;
picker.value = value;
picker.quickNavigate = options?.quickNavigateConfiguration;
picker.autoFocusSecondEntry = !!options?.quickNavigateConfiguration || !!options?.autoFocus?.autoFocusSecondEntry;
picker.valueSelection = options?.inputSelection ? [options.inputSelection.start, options.inputSelection.end] : [value.length, value.length];
picker.contextKey = descriptor?.contextKey;
picker.filterValue = (value: string) => value.substring(descriptor ? descriptor.prefix.length : 0);
......
......@@ -21,6 +21,11 @@ export interface IQuickAccessOptions {
* Allows to enable quick navigate support in quick input.
*/
quickNavigateConfiguration?: IQuickNavigateConfiguration;
/**
* Wether to select the second pick item by default instead of the first.
*/
autoFocus?: { autoFocusSecondEntry?: boolean }
}
export interface IQuickAccessController {
......
......@@ -110,7 +110,7 @@ export class NoTabsTitleControl extends TitleControl {
}
}
} else {
// @rebornix
// TODO@rebornix
// gesture tap should open the quick open
// editorGroupView will focus on the editor again when there are mouse/pointer/touch down events
// we need to wait a bit as `GesureEvent.Tap` is generated from `touchstart` and then `touchend` evnets, which are not an atom event.
......
......@@ -330,14 +330,9 @@ export class QuickOpenAction extends Action {
super(id, label);
this.prefix = prefix;
this.enabled = !!this.quickOpenService;
}
run(): Promise<void> {
// Show with prefix
async run(): Promise<void> {
this.quickOpenService.show(this.prefix);
return Promise.resolve(undefined);
}
}
......@@ -61,6 +61,7 @@ export class GotoSymbolQuickAccessProvider extends AbstractGotoSymbolQuickAccess
Registry.as<IQuickAccessRegistry>(Extensions.Quickaccess).registerQuickAccessProvider({
ctor: GotoSymbolQuickAccessProvider,
prefix: AbstractGotoSymbolQuickAccessProvider.PREFIX,
contextKey: 'inFileSymbolsPicker',
placeholder: localize('gotoSymbolQuickAccessPlaceholder', "Type the name of a symbol to go to."),
helpEntries: [
{ description: localize('gotoSymbolQuickAccess', "Go to Symbol in Editor"), prefix: AbstractGotoSymbolQuickAccessProvider.PREFIX, needsEditor: true },
......
......@@ -180,6 +180,7 @@ registerDebugCommandPaletteItem(TOGGLE_INLINE_BREAKPOINT_ID, nls.localize('inlin
Registry.as<IQuickAccessRegistry>(QuickAccessExtensions.Quickaccess).registerQuickAccessProvider({
ctor: StartDebugQuickAccessProvider,
prefix: StartDebugQuickAccessProvider.PREFIX,
contextKey: 'inLaunchConfigurationsPicker',
placeholder: nls.localize('startDebugPlaceholder', "Type the name of a launch configuration to run."),
helpEntries: [{ description: nls.localize('startDebugHelp', "Start Debug Configurations"), needsEditor: false }]
});
......
......@@ -22,6 +22,7 @@ registry.registerQuickAccessProvider({
registry.registerQuickAccessProvider({
ctor: ViewQuickAccessProvider,
prefix: ViewQuickAccessProvider.PREFIX,
contextKey: 'inViewsPicker',
placeholder: localize('viewQuickAccessPlaceholder', "Type the name of a view, output channel or terminal to open."),
helpEntries: [{ description: localize('viewQuickAccess', "Open View"), needsEditor: false }]
});
......@@ -29,6 +30,7 @@ registry.registerQuickAccessProvider({
registry.registerQuickAccessProvider({
ctor: CommandsQuickAccessProvider,
prefix: CommandsQuickAccessProvider.PREFIX,
contextKey: 'inCommandsPicker',
placeholder: localize('commandsQuickAccessPlaceholder', "Type the name of a command to run."),
helpEntries: [{ description: localize('commandsQuickAccess', "Show and Run Commands"), needsEditor: false }]
});
......@@ -34,6 +34,7 @@ import { Disposable, DisposableStore, IDisposable, toDisposable, dispose } from
import { timeout } from 'vs/base/common/async';
import { isFirefox } from 'vs/base/browser/browser';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { CommandsHistory } from 'vs/platform/quickinput/browser/commandsQuickAccess';
export const ALL_COMMANDS_PREFIX = '>';
......@@ -42,7 +43,7 @@ interface ISerializedCommandHistory {
entries: { key: string; value: number }[];
}
class CommandsHistory extends Disposable {
class LegacyCommandsHistory extends Disposable {
static readonly DEFAULT_COMMANDS_HISTORY_LENGTH = 50;
......@@ -71,17 +72,17 @@ class CommandsHistory extends Disposable {
}
private updateConfiguration(): void {
this.configuredCommandsHistoryLength = CommandsHistory.getConfiguredCommandHistoryLength(this.configurationService);
this.configuredCommandsHistoryLength = LegacyCommandsHistory.getConfiguredCommandHistoryLength(this.configurationService);
if (CommandsHistory.cache && CommandsHistory.cache.limit !== this.configuredCommandsHistoryLength) {
CommandsHistory.cache.limit = this.configuredCommandsHistoryLength;
if (LegacyCommandsHistory.cache && LegacyCommandsHistory.cache.limit !== this.configuredCommandsHistoryLength) {
LegacyCommandsHistory.cache.limit = this.configuredCommandsHistoryLength;
CommandsHistory.saveState(this.storageService);
LegacyCommandsHistory.saveState(this.storageService);
}
}
private load(): void {
const raw = this.storageService.get(CommandsHistory.PREF_KEY_CACHE, StorageScope.GLOBAL);
const raw = this.storageService.get(LegacyCommandsHistory.PREF_KEY_CACHE, StorageScope.GLOBAL);
let serializedCache: ISerializedCommandHistory | undefined;
if (raw) {
try {
......@@ -91,7 +92,7 @@ class CommandsHistory extends Disposable {
}
}
const cache = CommandsHistory.cache = new LRUCache<string, number>(this.configuredCommandsHistoryLength, 1);
const cache = LegacyCommandsHistory.cache = new LRUCache<string, number>(this.configuredCommandsHistoryLength, 1);
if (serializedCache) {
let entries: { key: string; value: number }[];
if (serializedCache.usesLRU) {
......@@ -102,33 +103,33 @@ class CommandsHistory extends Disposable {
entries.forEach(entry => cache.set(entry.key, entry.value));
}
CommandsHistory.counter = this.storageService.getNumber(CommandsHistory.PREF_KEY_COUNTER, StorageScope.GLOBAL, CommandsHistory.counter);
LegacyCommandsHistory.counter = this.storageService.getNumber(LegacyCommandsHistory.PREF_KEY_COUNTER, StorageScope.GLOBAL, LegacyCommandsHistory.counter);
}
push(commandId: string): void {
if (!CommandsHistory.cache) {
if (!LegacyCommandsHistory.cache) {
return;
}
CommandsHistory.cache.set(commandId, CommandsHistory.counter++); // set counter to command
LegacyCommandsHistory.cache.set(commandId, LegacyCommandsHistory.counter++); // set counter to command
CommandsHistory.saveState(this.storageService);
LegacyCommandsHistory.saveState(this.storageService);
}
peek(commandId: string): number | undefined {
return CommandsHistory.cache?.peek(commandId);
return LegacyCommandsHistory.cache?.peek(commandId);
}
static saveState(storageService: IStorageService): void {
if (!CommandsHistory.cache) {
if (!LegacyCommandsHistory.cache) {
return;
}
const serializedCache: ISerializedCommandHistory = { usesLRU: true, entries: [] };
CommandsHistory.cache.forEach((value, key) => serializedCache.entries.push({ key, value }));
LegacyCommandsHistory.cache.forEach((value, key) => serializedCache.entries.push({ key, value }));
storageService.store(CommandsHistory.PREF_KEY_CACHE, JSON.stringify(serializedCache), StorageScope.GLOBAL);
storageService.store(CommandsHistory.PREF_KEY_COUNTER, CommandsHistory.counter, StorageScope.GLOBAL);
storageService.store(LegacyCommandsHistory.PREF_KEY_CACHE, JSON.stringify(serializedCache), StorageScope.GLOBAL);
storageService.store(LegacyCommandsHistory.PREF_KEY_COUNTER, LegacyCommandsHistory.counter, StorageScope.GLOBAL);
}
static getConfiguredCommandHistoryLength(configurationService: IConfigurationService): number {
......@@ -139,15 +140,15 @@ class CommandsHistory extends Disposable {
return configuredCommandHistoryLength;
}
return CommandsHistory.DEFAULT_COMMANDS_HISTORY_LENGTH;
return LegacyCommandsHistory.DEFAULT_COMMANDS_HISTORY_LENGTH;
}
static clearHistory(configurationService: IConfigurationService, storageService: IStorageService): void {
const commandHistoryLength = CommandsHistory.getConfiguredCommandHistoryLength(configurationService);
CommandsHistory.cache = new LRUCache<string, number>(commandHistoryLength);
CommandsHistory.counter = 1;
const commandHistoryLength = LegacyCommandsHistory.getConfiguredCommandHistoryLength(configurationService);
LegacyCommandsHistory.cache = new LRUCache<string, number>(commandHistoryLength);
LegacyCommandsHistory.counter = 1;
CommandsHistory.saveState(storageService);
LegacyCommandsHistory.saveState(storageService);
}
}
......@@ -197,13 +198,16 @@ export class ClearCommandHistoryAction extends Action {
super(id, label);
}
run(): Promise<void> {
async run(): Promise<void> {
const legacyCommandHistoryLength = LegacyCommandsHistory.getConfiguredCommandHistoryLength(this.configurationService);
if (legacyCommandHistoryLength > 0) {
LegacyCommandsHistory.clearHistory(this.configurationService, this.storageService);
}
const commandHistoryLength = CommandsHistory.getConfiguredCommandHistoryLength(this.configurationService);
if (commandHistoryLength > 0) {
CommandsHistory.clearHistory(this.configurationService, this.storageService);
}
return Promise.resolve(undefined);
}
}
......@@ -222,13 +226,11 @@ class CommandPaletteEditorAction extends EditorAction {
});
}
run(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
async run(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
const quickOpenService = accessor.get(IQuickOpenService);
// Show with prefix
quickOpenService.show(ALL_COMMANDS_PREFIX);
return Promise.resolve(undefined);
}
}
......@@ -406,7 +408,7 @@ export class CommandsHandler extends QuickOpenHandler implements IDisposable {
static readonly ID = 'workbench.picker.commands';
private commandHistoryEnabled: boolean | undefined;
private readonly commandsHistory: CommandsHistory;
private readonly commandsHistory: LegacyCommandsHistory;
private readonly disposables = new DisposableStore();
private readonly disposeOnClose = new DisposableStore();
......@@ -423,7 +425,7 @@ export class CommandsHandler extends QuickOpenHandler implements IDisposable {
) {
super();
this.commandsHistory = this.disposables.add(this.instantiationService.createInstance(CommandsHistory));
this.commandsHistory = this.disposables.add(this.instantiationService.createInstance(LegacyCommandsHistory));
this.extensionService.whenInstalledExtensionsRegistered().then(() => this.waitedForExtensionsRegistered = true);
......@@ -432,7 +434,7 @@ export class CommandsHandler extends QuickOpenHandler implements IDisposable {
}
private updateConfiguration(): void {
this.commandHistoryEnabled = CommandsHistory.getConfiguredCommandHistoryLength(this.configurationService) > 0;
this.commandHistoryEnabled = LegacyCommandsHistory.getConfiguredCommandHistoryLength(this.configurationService) > 0;
}
async getResults(searchValue: string, token: CancellationToken): Promise<QuickOpenModel> {
......
......@@ -22,6 +22,7 @@ import { isCodeEditor, isDiffEditor } from 'vs/editor/browser/editorBrowser';
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { Event } from 'vs/base/common/event';
import { CancellationToken } from 'vs/base/common/cancellation';
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
export const GOTO_LINE_PREFIX = ':';
......@@ -32,6 +33,7 @@ export class GotoLineAction extends QuickOpenAction {
constructor(actionId: string, actionLabel: string,
@IQuickOpenService quickOpenService: IQuickOpenService,
@IQuickInputService private readonly quickInputService: IQuickInputService,
@IEditorService private readonly editorService: IEditorService
) {
super(actionId, actionLabel, GOTO_LINE_PREFIX, quickOpenService);
......@@ -61,7 +63,7 @@ export class GotoLineAction extends QuickOpenAction {
const result = super.run();
if (restoreOptions) {
Event.once(this.quickOpenService.onHide)(() => {
Event.once(Event.any(this.quickOpenService.onHide, this.quickInputService.onHide))(() => {
activeTextEditorControl!.updateOptions(restoreOptions!);
});
}
......
......@@ -470,20 +470,21 @@ MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
class ShowAllSymbolsAction extends Action {
static readonly ID = 'workbench.action.showAllSymbols';
static readonly LABEL = nls.localize('showTriggerActions', "Go to Symbol in Workspace...");
static readonly ALL_SYMBOLS_PREFIX = '#';
constructor(
actionId: string, actionLabel: string,
actionId: string,
actionLabel: string,
@IQuickOpenService private readonly quickOpenService: IQuickOpenService,
@ICodeEditorService private readonly editorService: ICodeEditorService) {
@ICodeEditorService private readonly editorService: ICodeEditorService
) {
super(actionId, actionLabel);
this.enabled = !!this.quickOpenService;
}
run(context?: any): Promise<void> {
async run(): Promise<void> {
let prefix = ShowAllSymbolsAction.ALL_SYMBOLS_PREFIX;
let inputSelection: { start: number; end: number; } | undefined = undefined;
const editor = this.editorService.getFocusedCodeEditor();
......@@ -494,8 +495,6 @@ class ShowAllSymbolsAction extends Action {
}
this.quickOpenService.show(prefix, { inputSelection });
return Promise.resolve(undefined);
}
}
......@@ -661,7 +660,7 @@ quickAccessRegistry.registerQuickAccessProvider({
ctor: AnythingQuickAccessProvider,
prefix: AnythingQuickAccessProvider.PREFIX,
placeholder: nls.localize('anythingQuickAccessPlaceholder', "Type '?' to get help on the actions you can take from here"),
contextKey: 'inFilesPicker',
contextKey: defaultQuickOpenContextKey,
helpEntries: [{ description: nls.localize('anythingQuickAccess', "Go to File"), needsEditor: false }]
});
......
......@@ -137,7 +137,7 @@ export class QuickKillTerminalAction extends Action {
instance.dispose(true);
}
await timeout(50);
return this.quickOpenService.show(TERMINAL_PICKER_PREFIX, undefined);
return this.quickOpenService.show(TERMINAL_PICKER_PREFIX);
}
}
......@@ -1139,7 +1139,7 @@ export class QuickOpenTermAction extends Action {
}
public run(): Promise<void> {
return this.quickOpenService.show(TERMINAL_PICKER_PREFIX, undefined);
return this.quickOpenService.show(TERMINAL_PICKER_PREFIX);
}
}
......@@ -1160,7 +1160,7 @@ export class RenameTerminalQuickOpenAction extends RenameTerminalAction {
await super.run(this.terminal);
// This timeout is needed to make sure the previous quickOpen has time to close before we show the next one
await timeout(50);
await this.quickOpenService.show(TERMINAL_PICKER_PREFIX, undefined);
await this.quickOpenService.show(TERMINAL_PICKER_PREFIX);
}
}
......
......@@ -179,7 +179,6 @@ import 'vs/workbench/contrib/scm/browser/scmViewlet';
// Debug
import 'vs/workbench/contrib/debug/browser/debug.contribution';
import 'vs/workbench/contrib/debug/browser/debugQuickOpen';
import 'vs/workbench/contrib/debug/browser/debugEditorContribution';
import 'vs/workbench/contrib/debug/browser/breakpointEditorContribution';
import 'vs/workbench/contrib/debug/browser/callStackEditorContribution';
......@@ -201,7 +200,6 @@ import 'vs/workbench/contrib/customEditor/browser/webviewEditor.contribution';
// Extensions Management
import 'vs/workbench/contrib/extensions/browser/extensions.contribution';
import 'vs/workbench/contrib/extensions/browser/extensionsQuickOpen';
import 'vs/workbench/contrib/extensions/browser/extensionsViewlet';
// Output View
......@@ -210,7 +208,6 @@ import 'vs/workbench/contrib/output/browser/outputView';
// Terminal
import 'vs/workbench/contrib/terminal/browser/terminal.contribution';
import 'vs/workbench/contrib/terminal/browser/terminalQuickOpen';
import 'vs/workbench/contrib/terminal/browser/terminalView';
// Relauncher
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册