Skip to content

Commit

Permalink
[quick-open] disable separate fuzzy substring matching by default #4537
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Mar 13, 2019
1 parent 2bd0e8f commit ccb399d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

Breaking changes:
- [editor] computation of resource context keys moved to core [#4531](https://github.com/theia-ide/theia/pull/4531)
- [quick-open] disable separate fuzzy matching by default [#4549](https://github.com/theia-ide/theia/pull/4549)

## v0.4.0
- [application-manager] added support for pre-load HTML templates
Expand Down
12 changes: 9 additions & 3 deletions packages/core/src/browser/quick-open/quick-open-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ import { MessageType } from '../../common/message-service-protocol';

export type QuickOpenOptions = Partial<QuickOpenOptions.Resolved>;
export namespace QuickOpenOptions {
export interface FuzzyMatchOptions {
/**
* Default: `false`
*/
enableSeparateSubstringMatching?: boolean
}
export interface Resolved {
readonly prefix: string;
readonly placeholder: string;
readonly ignoreFocusOut: boolean;

readonly fuzzyMatchLabel: boolean;
readonly fuzzyMatchDetail: boolean;
readonly fuzzyMatchDescription: boolean;
readonly fuzzyMatchLabel: boolean | FuzzyMatchOptions;
readonly fuzzyMatchDetail: boolean | FuzzyMatchOptions;
readonly fuzzyMatchDescription: boolean | FuzzyMatchOptions;
readonly fuzzySort: boolean;

/** The amount of first symbols to be ignored by quick open widget (e.g. don't affect matching). */
Expand Down
8 changes: 6 additions & 2 deletions packages/file-search/src/browser/quick-file-open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ export class QuickFileOpenService implements QuickOpenModel, QuickOpenHandler {
}
return {
placeholder,
fuzzyMatchLabel: true,
fuzzyMatchDescription: true,
fuzzyMatchLabel: {
enableSeparateSubstringMatching: true
},
fuzzyMatchDescription: {
enableSeparateSubstringMatching: true
},
showItemsWithoutHighlight: true,
onClose: () => {
this.isOpen = false;
Expand Down
12 changes: 7 additions & 5 deletions packages/monaco/src/browser/monaco-quick-open-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,10 @@ export class MonacoQuickOpenControllerOptsImpl implements MonacoQuickOpenControl
if (this.options.skipPrefix) {
lookFor = lookFor.substr(this.options.skipPrefix);
}
const labelHighlights = this.options.fuzzyMatchLabel ? this.matchesFuzzy(lookFor, item.getLabel()) : item.getLabelHighlights();
const descriptionHighlights = this.options.fuzzyMatchDescription ? this.matchesFuzzy(lookFor, item.getDescription()) : item.getDescriptionHighlights();
const detailHighlights = this.options.fuzzyMatchDetail ? this.matchesFuzzy(lookFor, item.getDetail()) : item.getDetailHighlights();
const { fuzzyMatchLabel, fuzzyMatchDescription, fuzzyMatchDetail } = this.options;
const labelHighlights = fuzzyMatchLabel ? this.matchesFuzzy(lookFor, item.getLabel(), fuzzyMatchLabel) : item.getLabelHighlights();
const descriptionHighlights = fuzzyMatchDescription ? this.matchesFuzzy(lookFor, item.getDescription(), fuzzyMatchDescription) : item.getDescriptionHighlights();
const detailHighlights = fuzzyMatchDetail ? this.matchesFuzzy(lookFor, item.getDetail(), fuzzyMatchDetail) : item.getDetailHighlights();
if ((lookFor && !labelHighlights && !descriptionHighlights && !detailHighlights)
&& !this.options.showItemsWithoutHighlight) {
return undefined;
Expand All @@ -256,11 +257,12 @@ export class MonacoQuickOpenControllerOptsImpl implements MonacoQuickOpenControl
return entry;
}

protected matchesFuzzy(lookFor: string, value: string | undefined): monaco.quickOpen.IHighlight[] | undefined {
protected matchesFuzzy(lookFor: string, value: string | undefined, options?: QuickOpenOptions.FuzzyMatchOptions | boolean): monaco.quickOpen.IHighlight[] | undefined {
if (!lookFor || !value) {
return undefined;
}
return monaco.filters.matchesFuzzy(lookFor, value, true);
const enableSeparateSubstringMatching = typeof options === 'object' && options.enableSeparateSubstringMatching;
return monaco.filters.matchesFuzzy(lookFor, value, enableSeparateSubstringMatching);
}

getAutoFocus(lookFor: string): monaco.quickOpen.IAutoFocus {
Expand Down

0 comments on commit ccb399d

Please sign in to comment.