From ffef57eed1d5395dc06bc68fd8100f713874342a Mon Sep 17 00:00:00 2001 From: abaevbog Date: Sat, 11 May 2024 03:21:59 -0400 Subject: [PATCH] redone fix of focus sticking to tab after click (#4087) - revert debcb9944d19862565435fe0b8768c95c3dc633f since it breaks drag-drop reordering of tabs - when reader is being refocused by contextPane, add a small delay so that the focus settles on the tab before focusing the reader - also explicitly refocus the reader tab after drag, since then focus also lands on the tab and finds itself outside of the reader --- chrome/content/zotero/components/tabBar.jsx | 3 +-- chrome/content/zotero/elements/contextPane.js | 6 +++++- chrome/content/zotero/tabs.js | 13 +++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/components/tabBar.jsx b/chrome/content/zotero/components/tabBar.jsx index b8a00551a7..568898ef46 100644 --- a/chrome/content/zotero/components/tabBar.jsx +++ b/chrome/content/zotero/components/tabBar.jsx @@ -128,8 +128,6 @@ const TabBar = forwardRef(function (props, ref) { } props.onTabSelect(id); event.stopPropagation(); - // Prevents focus from sticking to the actual tab on windows - event.preventDefault(); } function handleTabClick(event, id) { @@ -162,6 +160,7 @@ const TabBar = forwardRef(function (props, ref) { function handleDragEnd() { setDragging(false); + props.refocusReader(); } function handleTabBarDragOver(event) { diff --git a/chrome/content/zotero/elements/contextPane.js b/chrome/content/zotero/elements/contextPane.js index 881d6731b1..11b3531bb3 100644 --- a/chrome/content/zotero/elements/contextPane.js +++ b/chrome/content/zotero/elements/contextPane.js @@ -203,7 +203,11 @@ || !document.activeElement.closest('.context-node iframe[id="editor-view"]'))) { if (!Zotero_Tabs.focusOptions?.keepTabFocused) { // Do not move focus to the reader during keyboard navigation - reader.focus(); + setTimeout(() => { + // Timeout to make sure focus does not stick to the tab + // after click on windows + reader.focus(); + }); } } diff --git a/chrome/content/zotero/tabs.js b/chrome/content/zotero/tabs.js index 104610f333..cc76407da8 100644 --- a/chrome/content/zotero/tabs.js +++ b/chrome/content/zotero/tabs.js @@ -161,6 +161,7 @@ var Zotero_Tabs = new function () { onTabMove={this.move.bind(this)} onTabClose={this.close.bind(this)} onContextMenu={this._openMenu.bind(this)} + refocusReader={this.refocusReader.bind(this)} />, document.getElementById('tab-bar-container'), () => { @@ -569,6 +570,18 @@ var Zotero_Tabs = new function () { this.select(this._tabs[this._tabs.length - 1].id); }; + /** + * Return focus into the reader of the selected tab. + * Required to move focus from the tab into the reader after drag. + */ + this.refocusReader = function () { + var reader = Zotero.Reader.getByTabID(this._selectedID); + if (!reader) return; + setTimeout(() => { + reader.focus(); + }); + } + /** * Moves focus to a tab in the specified direction. * @param {String} direction. "first", "last", "left", "right", or "current"