Skip to content

Commit

Permalink
Implement search.quickOpen.includeHistory preference (#12913)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Radke <[email protected]>
  • Loading branch information
KR155E authored Oct 18, 2023
1 parent e0c82d1 commit 30d166e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
32 changes: 18 additions & 14 deletions packages/file-search/src/browser/quick-file-open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// *****************************************************************************

import { inject, injectable, optional, postConstruct } from '@theia/core/shared/inversify';
import { OpenerService, KeybindingRegistry, QuickAccessRegistry, QuickAccessProvider, CommonCommands } from '@theia/core/lib/browser';
import { OpenerService, KeybindingRegistry, QuickAccessRegistry, QuickAccessProvider, CommonCommands, PreferenceService } from '@theia/core/lib/browser';
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
import URI from '@theia/core/lib/common/uri';
import { FileSearchService, WHITESPACE_QUERY_SEPARATOR } from '../common/file-search-service';
Expand Down Expand Up @@ -66,6 +66,8 @@ export class QuickFileOpenService implements QuickAccessProvider {
protected readonly messageService: MessageService;
@inject(FileSystemPreferences)
protected readonly fsPreferences: FileSystemPreferences;
@inject(PreferenceService)
protected readonly preferences: PreferenceService;

registerQuickAccessProvider(): void {
this.quickAccessRegistry.registerQuickAccessProvider({
Expand Down Expand Up @@ -162,20 +164,22 @@ export class QuickFileOpenService implements QuickAccessProvider {
const alreadyCollected = new Set<string>();
const recentlyUsedItems: QuickPicks = [];

const locations = [...this.navigationLocationService.locations()].reverse();
for (const location of locations) {
const uriString = location.uri.toString();

if (location.uri.scheme === 'file' && !alreadyCollected.has(uriString) && fuzzy.test(fileFilter, uriString)) {
if (recentlyUsedItems.length === 0) {
recentlyUsedItems.push({
type: 'separator',
label: nls.localizeByDefault('recently opened')
});
if (this.preferences.get('search.quickOpen.includeHistory')) {
const locations = [...this.navigationLocationService.locations()].reverse();
for (const location of locations) {
const uriString = location.uri.toString();

if (location.uri.scheme === 'file' && !alreadyCollected.has(uriString) && fuzzy.test(fileFilter, uriString)) {
if (recentlyUsedItems.length === 0) {
recentlyUsedItems.push({
type: 'separator',
label: nls.localizeByDefault('recently opened')
});
}
const item = this.toItem(fileFilter, location.uri);
recentlyUsedItems.push(item);
alreadyCollected.add(uriString);
}
const item = this.toItem(fileFilter, location.uri);
recentlyUsedItems.push(item);
alreadyCollected.add(uriString);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export const searchInWorkspacePreferencesSchema: PreferenceSchema = {
type: 'string',
enum: ['auto', 'alwaysCollapse', 'alwaysExpand'],
},
'search.quickOpen.includeHistory': {
description: nls.localizeByDefault('Whether to include results from recently opened files in the file results for Quick Open.'),
default: true,
type: 'boolean',
},
'search.searchOnType': {
description: nls.localizeByDefault('Search all files as you type.'),
default: true,
Expand Down

0 comments on commit 30d166e

Please sign in to comment.