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

Commit 40df77e

Browse files
ruturajvjasonLaster
authored andcommitted
WIP - Bug 3038 editor search add text search button (#3100)
* Adding plain text search button to SearchBar * Worked on codehag suggestions * fixed some suggestions by codehag * Adding plain text search button to SearchBar * Worked on codehag suggestions * fixed some suggestions by codehag * fix up searchText * fix tests and make prettier happy
1 parent 9c0aa78 commit 40df77e

3 files changed

Lines changed: 86 additions & 25 deletions

File tree

src/components/Editor/SearchBar.js

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class SearchBar extends Component {
134134
self.closeSearch = this.closeSearch.bind(this);
135135
self.toggleSearch = this.toggleSearch.bind(this);
136136
self.toggleSymbolSearch = this.toggleSymbolSearch.bind(this);
137+
self.toggleTextSearch = this.toggleTextSearch.bind(this);
137138
self.setSearchValue = this.setSearchValue.bind(this);
138139
self.selectSearchInput = this.selectSearchInput.bind(this);
139140
self.searchInput = this.searchInput.bind(this);
@@ -297,24 +298,22 @@ class SearchBar extends Component {
297298
}
298299
}
299300

300-
toggleSymbolSearch(
301-
e: SyntheticKeyboardEvent,
302-
{ toggle, searchType }: ToggleSymbolSearchOpts = {}
303-
) {
304-
const { selectedSource } = this.props;
305-
301+
ignoreEvent(e) {
306302
if (e) {
307303
e.preventDefault();
308304
e.stopPropagation();
309305
}
306+
}
310307

308+
toggleSymbolSearch(
309+
e: SyntheticKeyboardEvent,
310+
{ toggle, searchType }: ToggleSymbolSearchOpts = {}
311+
) {
312+
const { selectedSource } = this.props;
311313
if (!selectedSource) {
312314
return;
313315
}
314-
315-
if (!this.props.searchOn) {
316-
this.props.toggleFileSearch();
317-
}
316+
this.ignoreEvent(e);
318317

319318
if (this.props.symbolSearchOn) {
320319
if (toggle) {
@@ -325,11 +324,25 @@ class SearchBar extends Component {
325324
return;
326325
}
327326

328-
if (this.props.selectedSource) {
329-
this.clearSearch();
330-
this.props.toggleSymbolSearch(true);
331-
this.props.setSelectedSymbolType(searchType);
327+
this.clearSearch();
328+
this.props.toggleSymbolSearch(true);
329+
this.props.setSelectedSymbolType(searchType);
330+
}
331+
332+
toggleTextSearch(e: SyntheticKeyboardEvent) {
333+
const { selectedSource } = this.props;
334+
this.ignoreEvent(e);
335+
336+
if (!selectedSource) {
337+
return;
338+
}
339+
340+
if (!this.props.searchOn) {
341+
this.props.toggleFileSearch();
332342
}
343+
344+
this.clearSearch();
345+
this.props.toggleSymbolSearch(false);
333346
}
334347

335348
setSearchValue(value: string) {
@@ -662,22 +675,45 @@ class SearchBar extends Component {
662675
}
663676

664677
renderSearchTypeToggle() {
665-
const { toggleSymbolSearch } = this;
678+
const { toggleSymbolSearch, toggleTextSearch } = this;
666679
const { symbolSearchOn, selectedSymbolType } = this.props;
667680

681+
function isButtonActive(searchType) {
682+
switch (searchType) {
683+
case "functions":
684+
case "variables":
685+
return symbolSearchOn && selectedSymbolType == searchType;
686+
// text search
687+
default:
688+
return !symbolSearchOn;
689+
}
690+
}
691+
692+
function searchTextBtn() {
693+
const searchType = "text";
694+
const active = isButtonActive(searchType);
695+
696+
return dom.button(
697+
{
698+
className: classnames("search-type-btn", {
699+
active
700+
}),
701+
onClick: e => toggleTextSearch(e)
702+
},
703+
searchType
704+
);
705+
}
706+
668707
function searchTypeBtn(searchType) {
708+
const active = isButtonActive(searchType);
709+
const toggle = selectedSymbolType == searchType;
710+
669711
return dom.button(
670712
{
671713
className: classnames("search-type-btn", {
672-
active: symbolSearchOn && selectedSymbolType == searchType
714+
active
673715
}),
674-
onClick: e => {
675-
if (selectedSymbolType == searchType) {
676-
toggleSymbolSearch(e, { toggle: true, searchType });
677-
return;
678-
}
679-
toggleSymbolSearch(e, { toggle: false, searchType });
680-
}
716+
onClick: e => toggleSymbolSearch(e, { toggle, searchType })
681717
},
682718
searchType
683719
);
@@ -689,6 +725,7 @@ class SearchBar extends Component {
689725
{ className: "search-toggle-title" },
690726
L10N.getStr("editor.searchTypeToggleTitle")
691727
),
728+
searchTextBtn(),
692729
searchTypeBtn("functions"),
693730
searchTypeBtn("variables")
694731
);

src/components/Editor/tests/__snapshots__/SearchBar.js.snap

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ ShallowWrapper {
3535
>
3636
Search for:
3737
</h1>
38+
<button
39+
className="search-type-btn"
40+
onClick={[Function]}
41+
>
42+
text
43+
</button>
3844
<button
3945
className="search-type-btn active"
4046
onClick={[Function]}
@@ -78,6 +84,12 @@ ShallowWrapper {
7884
>
7985
Search for:
8086
</h1>
87+
<button
88+
className="search-type-btn"
89+
onClick={[Function]}
90+
>
91+
text
92+
</button>
8193
<button
8294
className="search-type-btn active"
8395
onClick={[Function]}
@@ -153,6 +165,7 @@ ShallowWrapper {
153165
},
154166
"toggleSearch": [Function],
155167
"toggleSymbolSearch": [Function],
168+
"toggleTextSearch": [Function],
156169
"traverseCodeResults": [Function],
157170
"traverseResults": [Function],
158171
"traverseSymbolResults": [Function],
@@ -202,6 +215,12 @@ ShallowWrapper {
202215
>
203216
Search for:
204217
</h1>
218+
<button
219+
className="search-type-btn"
220+
onClick={[Function]}
221+
>
222+
text
223+
</button>
205224
<button
206225
className="search-type-btn active"
207226
onClick={[Function]}
@@ -245,6 +264,12 @@ ShallowWrapper {
245264
>
246265
Search for:
247266
</h1>
267+
<button
268+
className="search-type-btn"
269+
onClick={[Function]}
270+
>
271+
text
272+
</button>
248273
<button
249274
className="search-type-btn active"
250275
onClick={[Function]}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var foo = 1;
22
let bar = 2;
33
const baz = 3;
4-
const a = 4,
5-
b = 5;
4+
const a = 4, b = 5;

0 commit comments

Comments
 (0)