Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 7ca69e4

Browse files
committed
Speedup quick open (#5166)
1 parent 169ea16 commit 7ca69e4

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

src/components/QuickOpenModal.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import React, { Component } from "react";
88
import { connect } from "react-redux";
9-
import { filter } from "fuzzaldrin-plus";
9+
import fuzzyAldrin from "fuzzaldrin-plus";
1010

1111
import actions from "../actions";
1212
import {
@@ -61,6 +61,13 @@ type GotoLocationType = {
6161
column?: number
6262
};
6363

64+
function filter(values, query) {
65+
return fuzzyAldrin.filter(values, query, {
66+
key: "value",
67+
maxResults: 1000
68+
});
69+
}
70+
6471
export class QuickOpenModal extends Component<Props, State> {
6572
constructor(props: Props) {
6673
super(props);
@@ -98,10 +105,10 @@ export class QuickOpenModal extends Component<Props, State> {
98105

99106
if (this.isGotoSourceQuery()) {
100107
const [baseQuery] = query.split(":");
101-
const results = filter(this.props.sources, baseQuery, { key: "value" });
108+
const results = filter(this.props.sources, baseQuery);
102109
this.setState({ results });
103110
} else {
104-
const results = filter(this.props.sources, query, { key: "value" });
111+
const results = filter(this.props.sources, query);
105112
this.setState({ results });
106113
}
107114
};
@@ -117,9 +124,7 @@ export class QuickOpenModal extends Component<Props, State> {
117124
return this.setState({ results });
118125
}
119126

120-
results = filter(results, query.slice(1), {
121-
key: "value"
122-
});
127+
results = filter(results, query.slice(1));
123128

124129
this.setState({ results });
125130
};
@@ -128,13 +133,24 @@ export class QuickOpenModal extends Component<Props, State> {
128133
this.setState({ results: formatShortcutResults() });
129134
};
130135

136+
showTopSources = () => {
137+
const results = this.props.sources.slice(0, 100);
138+
this.setState({ results });
139+
};
140+
131141
updateResults = (query: string) => {
142+
if (query == "") {
143+
return this.showTopSources();
144+
}
145+
132146
if (this.isSymbolSearch()) {
133147
return this.searchSymbols(query);
134148
}
149+
135150
if (this.isShortcutQuery()) {
136151
return this.showShortcuts(query);
137152
}
153+
138154
return this.searchSources(query);
139155
};
140156

@@ -297,6 +313,7 @@ export class QuickOpenModal extends Component<Props, State> {
297313
searchType === "variables" ||
298314
searchType === "shortcuts";
299315

316+
const newResults = results && results.slice(0, 100);
300317
return (
301318
<Modal in={enabled} handleClose={this.closeModal}>
302319
<SearchInput
@@ -308,10 +325,10 @@ export class QuickOpenModal extends Component<Props, State> {
308325
onKeyDown={this.onKeyDown}
309326
handleClose={this.closeModal}
310327
/>
311-
{results && (
328+
{newResults && (
312329
<ResultList
313330
key="results"
314-
items={results}
331+
items={newResults}
315332
selected={selectedIndex}
316333
selectItem={this.selectResultItem}
317334
ref="resultList"

src/components/tests/QuickOpenModal.spec.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ describe("QuickOpenModal", () => {
122122
"mount"
123123
);
124124
wrapper.find("input").simulate("change", { target: { value: "somefil" } });
125-
expect(filter).toHaveBeenCalledWith([], "somefil", { key: "value" });
125+
expect(filter).toHaveBeenCalledWith([], "somefil", {
126+
key: "value",
127+
maxResults: 1000
128+
});
126129
});
127130

128131
test("basic gotoSource search", () => {
@@ -140,7 +143,10 @@ describe("QuickOpenModal", () => {
140143
wrapper
141144
.find("input")
142145
.simulate("change", { target: { value: "somefil:33" } });
143-
expect(filter).toHaveBeenCalledWith([], "somefil", { key: "value" });
146+
expect(filter).toHaveBeenCalledWith([], "somefil", {
147+
key: "value",
148+
maxResults: 1000
149+
});
144150
});
145151

146152
test("basic symbol seach", () => {
@@ -161,6 +167,9 @@ describe("QuickOpenModal", () => {
161167
wrapper
162168
.find("input")
163169
.simulate("change", { target: { value: "@someFunc" } });
164-
expect(filter).toHaveBeenCalledWith([], "someFunc", { key: "value" });
170+
expect(filter).toHaveBeenCalledWith([], "someFunc", {
171+
key: "value",
172+
maxResults: 1000
173+
});
165174
});
166175
});

0 commit comments

Comments
 (0)