Skip to content

Commit 00b2928

Browse files
committed
(searchbar) expose a new Mod+Enter shortcut to quickly get out
This is already doable with escape… But. Before, we could just press Tab to exit the searchbar easily. Now, pressing Tab correctly tabs through items next to the searchbar (like the "search all" checkbox). So this quick way of getting out the searchbar is gone. I felt like exposing a "submit search" action through Mod+Enter was a good idea, it seems it better fits the intent than "escaping" search bar. But I guess this is a bit nitpicking, we could also do without this?
1 parent bfe303b commit 00b2928

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

app/client/components/commandList.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type CommandName =
88
| 'find'
99
| 'findNext'
1010
| 'findPrev'
11+
| 'endSearch'
1112
| 'historyBack'
1213
| 'historyForward'
1314
| 'reloadPlugins'
@@ -187,6 +188,11 @@ export const groups: CommendGroupDef[] = [{
187188
name: 'findPrev',
188189
keys: ['Mod+Shift+G'],
189190
desc: 'Find previous occurrence',
191+
}, {
192+
name: 'endSearch',
193+
keys: ['Mod+Enter'],
194+
desc: 'When in the search bar, close it and focus the current match',
195+
alwaysOn: true,
190196
}, {
191197
// Without this, when focus in on Clipboard, this shortcut would only move the cursor.
192198
name: 'historyBack',

app/client/ui2018/search.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
import { allCommands, createGroup } from 'app/client/components/commands';
66
import { Panel, RegionFocusSwitcher } from 'app/client/components/RegionFocusSwitcher';
7+
import { modKeyProp } from 'app/client/lib/browserInfo';
78
import { makeT } from 'app/client/lib/localization';
89
import { reportError } from 'app/client/models/AppModel';
910
import { SearchModel } from 'app/client/models/SearchModel';
@@ -213,6 +214,10 @@ export function searchBar(model: SearchModel, testId: TestId = noTestId, regionF
213214
findPrev: () => { model.findPrev().catch(reportError); return false; },
214215
}, null, true);
215216

217+
const commandGroupWhenOpen = createGroup({
218+
endSearch: () => { toggleMenu(false); return false; },
219+
}, null, model.isOpen);
220+
216221
const inputElem: HTMLInputElement = searchInput(model.value, {onInput: true},
217222
{
218223
type: 'text',
@@ -223,16 +228,25 @@ export function searchBar(model: SearchModel, testId: TestId = noTestId, regionF
223228
focusedSearchElement = inputElem;
224229
}),
225230
dom.onKeyDown({
226-
Enter: (ev) => ev.shiftKey ? model.findPrev() : model.findNext(),
231+
// The $ lets the event propagate, in order to trigger the endSearch command correctly when focusing the input
232+
Enter$: async (ev) => {
233+
// If the user is pressing the mod key, don't do anything, the user is certainly trying to trigger endSearch
234+
if (ev[modKeyProp()] && !ev.shiftKey) {
235+
return;
236+
}
237+
return ev.shiftKey ? model.findPrev() : model.findNext();
238+
},
227239
}),
228240
commandGroup.attach(),
241+
commandGroupWhenOpen.attach(),
229242
);
230243

231244
return searchWrapper(
232245
testId('wrapper'),
233246
searchWrapper.cls('-expand', model.isOpen),
234247
dom.cls(wrapperClass),
235248
dom.autoDispose(commandGroup),
249+
dom.autoDispose(commandGroupWhenOpen),
236250
dom.onKeyDown({
237251
// The $ indicates to grainjs we don't want to stop propagation of the event here.
238252
// This handles the case where we are kb-focused on the search icon and press Esc:

0 commit comments

Comments
 (0)