Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commite5dfa84

Browse files
authored
Revert "Improve performance of "Go to file" (#8201)" (#8206)
This reverts commitee1c0c8.
1 parent3c4df3c commite5dfa84

File tree

6 files changed

+50
-94
lines changed

6 files changed

+50
-94
lines changed

‎src/components/QuickOpenModal.js‎

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import React, { Component } from "react";
77
import{connect}from"../utils/connect";
88
importfuzzyAldrinfrom"fuzzaldrin-plus";
99
import{basename}from"../utils/path";
10-
import{debounce}from"lodash";
1110

1211
importactionsfrom"../actions";
1312
import{
@@ -44,8 +43,8 @@ import "./QuickOpenModal.css";
4443

4544
typeProps={
4645
enabled:boolean,
46+
sources:Array<Object>,
4747
selectedSource?:Source,
48-
displayedSources:Source[],
4948
query:string,
5049
searchType:QuickOpenType,
5150
symbols:FormattedSymbolDeclarations,
@@ -70,16 +69,12 @@ type GotoLocationType = {
7069
column?:number
7170
};
7271

73-
constupdateResultsDebounce=100;
7472
constmaxResults=100;
7573

7674
functionfilter(values,query){
77-
constpreparedQuery=fuzzyAldrin.prepareQuery(query);
78-
7975
returnfuzzyAldrin.filter(values,query,{
8076
key:"value",
81-
maxResults:maxResults,
82-
preparedQuery
77+
maxResults:maxResults
8378
});
8479
}
8580

@@ -132,9 +127,7 @@ export class QuickOpenModal extends Component<Props, State> {
132127
};
133128

134129
searchSources=(query:string)=>{
135-
const{ displayedSources, tabs}=this.props;
136-
consttabUrls=newSet(tabs.map((tab:Tab)=>tab.url));
137-
constsources=formatSources(displayedSources,tabUrls);
130+
const{ sources}=this.props;
138131
constresults=
139132
query=="" ?sources :filter(sources,this.dropGoto(query));
140133
returnthis.setResults(results);
@@ -165,24 +158,16 @@ export class QuickOpenModal extends Component<Props, State> {
165158
};
166159

167160
showTopSources=()=>{
168-
const{ displayedSources, tabs}=this.props;
169-
consttabUrls=newSet(tabs.map((tab:Tab)=>tab.url));
170-
161+
const{ tabs, sources}=this.props;
171162
if(tabs.length>0){
172-
this.setResults(
173-
formatSources(
174-
displayedSources.filter(
175-
source=>!!source.url&&tabUrls.has(source.url)
176-
),
177-
tabUrls
178-
)
179-
);
163+
consttabUrls=tabs.map((tab:Tab)=>tab.url);
164+
this.setResults(sources.filter(source=>tabUrls.includes(source.url)));
180165
}else{
181-
this.setResults(formatSources(displayedSources,tabUrls));
166+
this.setResults(sources);
182167
}
183168
};
184169

185-
updateResults=debounce((query:string)=>{
170+
updateResults=(query:string)=>{
186171
if(this.isGotoQuery()){
187172
return;
188173
}
@@ -200,7 +185,7 @@ export class QuickOpenModal extends Component<Props, State> {
200185
}
201186

202187
returnthis.searchSources(query);
203-
},updateResultsDebounce);
188+
};
204189

205190
setModifier=(item:QuickOpenResult)=>{
206191
if(["@","#",":"].includes(item.id)){
@@ -437,17 +422,16 @@ export class QuickOpenModal extends Component<Props, State> {
437422
/* istanbul ignore next: ignoring testing of redux connection stuff */
438423
functionmapStateToProps(state){
439424
constselectedSource=getSelectedSource(state);
440-
consttabs=getTabs(state);
441425

442426
return{
443427
enabled:getQuickOpenEnabled(state),
428+
sources:formatSources(getDisplayedSourcesList(state),getTabs(state)),
444429
selectedSource,
445-
displayedSources:getDisplayedSourcesList(state),
446430
symbols:formatSymbols(getSymbols(state,selectedSource)),
447431
symbolsLoading:isSymbolsLoading(state,selectedSource),
448432
query:getQuickOpenQuery(state),
449433
searchType:getQuickOpenType(state),
450-
tabs
434+
tabs:getTabs(state)
451435
};
452436
}
453437

‎src/components/test/QuickOpenModal.spec.js‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@
77

88
importReactfrom"react";
99
import{shallow,mount}from"enzyme";
10-
importlodashfrom"lodash";
1110
import{QuickOpenModal}from"../QuickOpenModal";
1211

1312
jest.mock("fuzzaldrin-plus");
14-
jest.unmock("lodash");
15-
16-
// $FlowIgnore
17-
lodash.debounce=jest.fn(fn=>fn);
1813

1914
import{filter}from"fuzzaldrin-plus";
2015

@@ -23,7 +18,7 @@ function generateModal(propOverrides, renderType = "shallow") {
2318
enabled:false,
2419
query:"",
2520
searchType:"sources",
26-
displayedSources:[],
21+
sources:[],
2722
tabs:[],
2823
selectSpecificLocation:jest.fn(),
2924
setQuickOpenQuery:jest.fn(),
@@ -116,24 +111,12 @@ describe("QuickOpenModal", () => {
116111
{
117112
enabled:true,
118113
query:"",
119-
displayedSources:[
120-
// $FlowIgnore
121-
{url:"mozilla.com",relativeUrl:true}
122-
],
114+
sources:[{url:"mozilla.com"}],
123115
tabs:[generateTab("mozilla.com")]
124116
},
125117
"shallow"
126118
);
127-
expect(wrapper.state("results")).toEqual([
128-
{
129-
id:undefined,
130-
icon:"tab result-item-icon",
131-
subtitle:"true",
132-
title:"mozilla.com",
133-
url:"mozilla.com",
134-
value:"true"
135-
}
136-
]);
119+
expect(wrapper.state("results")).toEqual([{url:"mozilla.com"}]);
137120
});
138121

139122
describe("shows loading",()=>{
@@ -803,7 +786,6 @@ describe("QuickOpenModal", () => {
803786
},
804787
"mount"
805788
);
806-
807789
expect(wrapper).toMatchSnapshot();
808790
});
809791

‎src/components/test/__snapshots__/QuickOpenModal.spec.js.snap‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ exports[`QuickOpenModal Basic render with mount & searchType = functions 1`] = `
44
<QuickOpenModal
55
clearHighlightLineRange={[MockFunction]}
66
closeQuickOpen={[MockFunction]}
7-
displayedSources={Array []}
87
enabled={true}
98
highlightLineRange={[MockFunction]}
109
isOriginal={false}
@@ -13,6 +12,7 @@ exports[`QuickOpenModal Basic render with mount & searchType = functions 1`] = `
1312
selectSpecificLocation={[MockFunction]}
1413
setQuickOpenQuery={[MockFunction]}
1514
shortcutsModalEnabled={false}
15+
sources={Array []}
1616
symbols={
1717
Object {
1818
"functions":Array [],
@@ -130,7 +130,6 @@ exports[`QuickOpenModal Basic render with mount & searchType = variables 1`] = `
130130
<QuickOpenModal
131131
clearHighlightLineRange={[MockFunction]}
132132
closeQuickOpen={[MockFunction]}
133-
displayedSources={Array []}
134133
enabled={true}
135134
highlightLineRange={[MockFunction]}
136135
isOriginal={false}
@@ -139,6 +138,7 @@ exports[`QuickOpenModal Basic render with mount & searchType = variables 1`] = `
139138
selectSpecificLocation={[MockFunction]}
140139
setQuickOpenQuery={[MockFunction]}
141140
shortcutsModalEnabled={false}
141+
sources={Array []}
142142
symbols={
143143
Object {
144144
"functions":Array [],
@@ -240,7 +240,6 @@ exports[`QuickOpenModal Basic render with mount 1`] = `
240240
<QuickOpenModal
241241
clearHighlightLineRange={[MockFunction]}
242242
closeQuickOpen={[MockFunction]}
243-
displayedSources={Array []}
244243
enabled={true}
245244
highlightLineRange={[MockFunction]}
246245
isOriginal={false}
@@ -249,6 +248,7 @@ exports[`QuickOpenModal Basic render with mount 1`] = `
249248
selectSpecificLocation={[MockFunction]}
250249
setQuickOpenQuery={[MockFunction]}
251250
shortcutsModalEnabled={false}
251+
sources={Array []}
252252
symbols={
253253
Object {
254254
"functions":Array [],
@@ -400,7 +400,6 @@ exports[`QuickOpenModal Simple goto search query = :abc & searchType = goto 1`]
400400
<QuickOpenModal
401401
clearHighlightLineRange={[MockFunction]}
402402
closeQuickOpen={[MockFunction]}
403-
displayedSources={Array []}
404403
enabled={true}
405404
highlightLineRange={[MockFunction]}
406405
isOriginal={false}
@@ -409,6 +408,7 @@ exports[`QuickOpenModal Simple goto search query = :abc & searchType = goto 1`]
409408
selectSpecificLocation={[MockFunction]}
410409
setQuickOpenQuery={[MockFunction]}
411410
shortcutsModalEnabled={false}
411+
sources={Array []}
412412
symbols={
413413
Object {
414414
"functions":Array [],
@@ -515,7 +515,6 @@ exports[`QuickOpenModal showErrorEmoji false when count + query 1`] = `
515515
<QuickOpenModal
516516
clearHighlightLineRange={[MockFunction]}
517517
closeQuickOpen={[MockFunction]}
518-
displayedSources={Array []}
519518
enabled={true}
520519
highlightLineRange={[MockFunction]}
521520
isOriginal={false}
@@ -524,6 +523,7 @@ exports[`QuickOpenModal showErrorEmoji false when count + query 1`] = `
524523
selectSpecificLocation={[MockFunction]}
525524
setQuickOpenQuery={[MockFunction]}
526525
shortcutsModalEnabled={false}
526+
sources={Array []}
527527
symbols={
528528
Object {
529529
"functions":Array [],
@@ -672,7 +672,6 @@ exports[`QuickOpenModal showErrorEmoji false when goto numeric ':2222' 1`] = `
672672
<QuickOpenModal
673673
clearHighlightLineRange={[MockFunction]}
674674
closeQuickOpen={[MockFunction]}
675-
displayedSources={Array []}
676675
enabled={true}
677676
highlightLineRange={[MockFunction]}
678677
isOriginal={false}
@@ -681,6 +680,7 @@ exports[`QuickOpenModal showErrorEmoji false when goto numeric ':2222' 1`] = `
681680
selectSpecificLocation={[MockFunction]}
682681
setQuickOpenQuery={[MockFunction]}
683682
shortcutsModalEnabled={false}
683+
sources={Array []}
684684
symbols={
685685
Object {
686686
"functions":Array [],
@@ -786,7 +786,6 @@ exports[`QuickOpenModal showErrorEmoji false when no query 1`] = `
786786
<QuickOpenModal
787787
clearHighlightLineRange={[MockFunction]}
788788
closeQuickOpen={[MockFunction]}
789-
displayedSources={Array []}
790789
enabled={true}
791790
highlightLineRange={[MockFunction]}
792791
isOriginal={false}
@@ -795,6 +794,7 @@ exports[`QuickOpenModal showErrorEmoji false when no query 1`] = `
795794
selectSpecificLocation={[MockFunction]}
796795
setQuickOpenQuery={[MockFunction]}
797796
shortcutsModalEnabled={false}
797+
sources={Array []}
798798
symbols={
799799
Object {
800800
"functions":Array [],
@@ -911,7 +911,6 @@ exports[`QuickOpenModal showErrorEmoji true when goto not numeric ':22k22' 1`] =
911911
<QuickOpenModal
912912
clearHighlightLineRange={[MockFunction]}
913913
closeQuickOpen={[MockFunction]}
914-
displayedSources={Array []}
915914
enabled={true}
916915
highlightLineRange={[MockFunction]}
917916
isOriginal={false}
@@ -920,6 +919,7 @@ exports[`QuickOpenModal showErrorEmoji true when goto not numeric ':22k22' 1`] =
920919
selectSpecificLocation={[MockFunction]}
921920
setQuickOpenQuery={[MockFunction]}
922921
shortcutsModalEnabled={false}
922+
sources={Array []}
923923
symbols={
924924
Object {
925925
"functions":Array [],
@@ -1025,7 +1025,6 @@ exports[`QuickOpenModal showErrorEmoji true when no count + query 1`] = `
10251025
<QuickOpenModal
10261026
clearHighlightLineRange={[MockFunction]}
10271027
closeQuickOpen={[MockFunction]}
1028-
displayedSources={Array []}
10291028
enabled={true}
10301029
highlightLineRange={[MockFunction]}
10311030
isOriginal={false}
@@ -1034,6 +1033,7 @@ exports[`QuickOpenModal showErrorEmoji true when no count + query 1`] = `
10341033
selectSpecificLocation={[MockFunction]}
10351034
setQuickOpenQuery={[MockFunction]}
10361035
shortcutsModalEnabled={false}
1036+
sources={Array []}
10371037
symbols={
10381038
Object {
10391039
"functions":Array [],
@@ -1167,7 +1167,6 @@ exports[`QuickOpenModal updateResults on enable 1`] = `
11671167
<QuickOpenModal
11681168
clearHighlightLineRange={[MockFunction]}
11691169
closeQuickOpen={[MockFunction]}
1170-
displayedSources={Array []}
11711170
enabled={false}
11721171
highlightLineRange={[MockFunction]}
11731172
isOriginal={false}
@@ -1176,6 +1175,7 @@ exports[`QuickOpenModal updateResults on enable 1`] = `
11761175
selectSpecificLocation={[MockFunction]}
11771176
setQuickOpenQuery={[MockFunction]}
11781177
shortcutsModalEnabled={false}
1178+
sources={Array []}
11791179
symbols={
11801180
Object {
11811181
"functions":Array [],
@@ -1192,7 +1192,6 @@ exports[`QuickOpenModal updateResults on enable 2`] = `
11921192
<QuickOpenModal
11931193
clearHighlightLineRange={[MockFunction]}
11941194
closeQuickOpen={[MockFunction]}
1195-
displayedSources={Array []}
11961195
enabled={true}
11971196
highlightLineRange={[MockFunction]}
11981197
isOriginal={false}
@@ -1201,6 +1200,7 @@ exports[`QuickOpenModal updateResults on enable 2`] = `
12011200
selectSpecificLocation={[MockFunction]}
12021201
setQuickOpenQuery={[MockFunction]}
12031202
shortcutsModalEnabled={false}
1203+
sources={Array []}
12041204
symbols={
12051205
Object {
12061206
"functions":Array [],

‎src/utils/quick-open.js‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
importtype{LocationasBabelLocation}from"@babel/types";
1515
importtype{Symbols}from"../reducers/ast";
1616
importtype{QuickOpenType}from"../reducers/quick-open";
17-
importtype{Tab}from"../reducers/tabs";
17+
importtype{TabList}from"../reducers/tabs";
1818
importtype{Source}from"../types";
1919
importtype{
2020
SymbolDeclaration,
@@ -58,10 +58,7 @@ export function parseLineColumn(query: string) {
5858
}
5959
}
6060

61-
exportfunctionformatSourcesForList(
62-
source:Source,
63-
tabUrls:Set<$PropertyType<Tab,"url">>
64-
){
61+
exportfunctionformatSourcesForList(source:Source,tabs:TabList){
6562
consttitle=getFilename(source);
6663
constrelativeUrlWithQuery=`${source.relativeUrl}${getSourceQueryString(
6764
source
@@ -71,7 +68,7 @@ export function formatSourcesForList(
7168
value:relativeUrlWithQuery,
7269
title,
7370
subtitle:relativeUrlWithQuery,
74-
icon:tabUrls.has(source.url)
71+
icon:tabs.some(tab=>tab.url==source.url)
7572
?"tab result-item-icon"
7673
:classnames(getSourceClassnames(source),"result-item-icon"),
7774
id:source.id,
@@ -139,9 +136,10 @@ export function formatShortcutResults(): Array<QuickOpenResult> {
139136

140137
exportfunctionformatSources(
141138
sources:Source[],
142-
tabUrls:Set<$PropertyType<Tab,"url">>
139+
tabs:TabList
143140
):Array<QuickOpenResult>{
144141
returnsources
145-
.filter(source=>!!source.relativeUrl&&!isPretty(source))
146-
.map(source=>formatSourcesForList(source,tabUrls));
142+
.filter(source=>!isPretty(source))
143+
.filter(({ relativeUrl})=>!!relativeUrl)
144+
.map(source=>formatSourcesForList(source,tabs));
147145
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp