Skip to content

Commit

Permalink
Fix empty find popup not closing when focusing a view on Firefox/Zotero
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtcode committed Mar 4, 2024
1 parent 75dc9ec commit 16cf97d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/common/focus-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,25 @@ export class FocusManager {
});
}

_closeFindPopupIfEmpty() {
let state = this._reader._state.primaryViewFindState;
if (state && !state.query) {
this._reader._updateState({ primaryViewFindState: { ...state, popupOpen: false } });
}
state = this._reader._state.secondaryViewState;
if (state && !state.query) {
this._reader._updateState({ secondaryViewState: { ...state, popupOpen: false } });
}
}

_handleFocus(event) {
if ('closest' in event.target) {
if (!event.target.closest('.annotation, .annotation-popup, .selection-popup, .label-popup, .context-menu, iframe')) {
this._onDeselectAnnotations();
}
// Close find popup on blur if search query is empty
if (!event.target.closest('.find-popup')) {
let state = this._reader._state.primaryViewFindState;
if (state && !state.query) {
this._reader._updateState({ primaryViewFindState: { ...state, popupOpen: false } });
}
state = this._reader._state.secondaryViewState;
if (state && !state.query) {
this._reader._updateState({ secondaryViewState: { ...state, popupOpen: false } });
}
this._closeFindPopupIfEmpty();
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/common/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,8 @@ class Reader {

let onFocus = () => {
this.focusView(primary);
// A workaround for Firefox/Zotero because iframe focusing doesn't trigger 'focusin' event
this._focusManager._closeFindPopupIfEmpty();
};

let onRequestPassword = () => {
Expand Down

0 comments on commit 16cf97d

Please sign in to comment.