Skip to content

Commit aec5514

Browse files
ramonmimrtcode
authored andcommitted
feat: add openFindBar to open the note search bar
1 parent 107ab75 commit aec5514

4 files changed

Lines changed: 19 additions & 6 deletions

File tree

src/core/editor-core.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,10 @@ class EditorCore {
483483
this.view.focus();
484484
}
485485

486+
openFindbar() {
487+
this.pluginState.search.openFindbar();
488+
}
489+
486490
getData(onlyChanged) {
487491
if (onlyChanged && !this.docChanged) {
488492
return null;

src/core/plugins/search.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { removeDiacritics } from '../utils';
77
class Search {
88
constructor(options = {}) {
99
this.active = false;
10+
this.openFindbarRequestID = 0;
1011
this.searchTerm = '';
1112
this.caseSensitive = false;
1213
this.wholeWords = false;
@@ -53,6 +54,14 @@ class Search {
5354
dispatch(state.tr);
5455
}
5556

57+
openFindbar() {
58+
let { state, dispatch } = this.view;
59+
this.active = true;
60+
this.openFindbarRequestID += 1;
61+
this.triggerUpdate = true;
62+
dispatch(state.tr);
63+
}
64+
5665
setSearchTerm(searchTerm) {
5766
let { state, dispatch } = this.view;
5867
this.searchTerm = searchTerm;

src/index.zotero.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ class EditorInstance {
283283
this._focusToolbar();
284284
return;
285285
}
286+
case 'openFindBar': {
287+
this._editorCore.openFindbar();
288+
return;
289+
}
286290
case 'setFont': {
287291
let { font } = message;
288292
this._setFont(font);

src/ui/findbar.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ function Findbar({ searchState, active }) {
2929
if ((!isMac() && event.ctrlKey || isMac() && event.metaKey) && event.key === 'f') {
3030
event.preventDefault();
3131
event.stopPropagation();
32-
searchState.setActive(true);
33-
setTimeout(() => {
34-
searchInputRef.current?.focus();
35-
searchInputRef.current?.select();
36-
});
32+
searchState.openFindbar();
3733
return;
3834
}
3935

@@ -63,7 +59,7 @@ function Findbar({ searchState, active }) {
6359
}
6460
}, 100);
6561
}
66-
}, [active]);
62+
}, [active, searchState.openFindbarRequestID]);
6763

6864
function handleMouseDown(event) {
6965
if (event.target.nodeName !== 'INPUT') {

0 commit comments

Comments
 (0)