Find in a deck column; the app menu no longer closes on a passing blur
Ctrl+F pressed in a deck column (or in the shell while a deck is in front, for its focused column) opens that column's own find bar, laid over the column's header; F3 and Shift+F3 step through it. Same bar, same `tab_find`. The app menu closed on any window blur. Taking the keyboard from a focused tab (Alt+F / F10 forwarded by the tab, then `shell_focus`) can pass through a blur on its way to the shell, which closed the menu a few milliseconds after it opened. It now closes on blur only if the focus is still away a moment later. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1356d9364a
commit
eb2bc62ad4
4 changed files with 30 additions and 3 deletions
|
|
@ -167,7 +167,11 @@ export function AppMenu() {
|
||||||
// Native tab webviews would cover the menu.
|
// Native tab webviews would cover the menu.
|
||||||
setOverlay(1);
|
setOverlay(1);
|
||||||
noteOpen(anchor.at);
|
noteOpen(anchor.at);
|
||||||
const away = () => close();
|
// The window lost the keyboard: the menu closes, unless the focus is back a moment later (taking the
|
||||||
|
// keyboard from a tab for Alt+F / F10 can pass through a blur on its way to the shell).
|
||||||
|
let leaving: ReturnType<typeof setTimeout> | undefined;
|
||||||
|
const away = () => { clearTimeout(leaving); leaving = setTimeout(() => { if (!document.hasFocus()) close(); }, 160); };
|
||||||
|
const resized = () => close();
|
||||||
// Keys while nothing in the menu has focus (a click on its padding): Esc closes, arrows enter it.
|
// Keys while nothing in the menu has focus (a click on its padding): Esc closes, arrows enter it.
|
||||||
const onKey = (event: KeyboardEvent) => {
|
const onKey = (event: KeyboardEvent) => {
|
||||||
if (layers.current?.contains(event.target as Node)) return;
|
if (layers.current?.contains(event.target as Node)) return;
|
||||||
|
|
@ -179,9 +183,9 @@ export function AppMenu() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
window.addEventListener('blur', away);
|
window.addEventListener('blur', away);
|
||||||
window.addEventListener('resize', away);
|
window.addEventListener('resize', resized);
|
||||||
window.addEventListener('keydown', onKey);
|
window.addEventListener('keydown', onKey);
|
||||||
return () => { setOverlay(-1); noteOpen(null); window.removeEventListener('blur', away); window.removeEventListener('resize', away); window.removeEventListener('keydown', onKey); };
|
return () => { clearTimeout(leaving); setOverlay(-1); noteOpen(null); window.removeEventListener('blur', away); window.removeEventListener('resize', resized); window.removeEventListener('keydown', onKey); };
|
||||||
}, [open, anchor.at]);
|
}, [open, anchor.at]);
|
||||||
|
|
||||||
const layer = (level: number) => layers.current?.querySelector<HTMLElement>(`[data-level="${level}"]`) ?? null;
|
const layer = (level: number) => layers.current?.querySelector<HTMLElement>(`[data-level="${level}"]`) ?? null;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import {
|
||||||
addColumn, bump, columnSourceUrl, configureColumn, deckById, decks, patchColumn, removeColumn, shiftColumn,
|
addColumn, bump, columnSourceUrl, configureColumn, deckById, decks, patchColumn, removeColumn, shiftColumn,
|
||||||
type Deck, type DeckColumn,
|
type Deck, type DeckColumn,
|
||||||
} from './deckStore.ts';
|
} from './deckStore.ts';
|
||||||
|
import { FindBar } from './FindBar.tsx';
|
||||||
import { useDecks, useProfiles, useT } from './hooks.ts';
|
import { useDecks, useProfiles, useT } from './hooks.ts';
|
||||||
import { Icon, type IconName } from './icons.tsx';
|
import { Icon, type IconName } from './icons.tsx';
|
||||||
import { site } from './site.ts';
|
import { site } from './site.ts';
|
||||||
|
|
@ -181,6 +182,13 @@ function ColumnView({ deck, column, x, width, focused, number }: { deck: Deck; c
|
||||||
const still = useTabStill(column.tabId);
|
const still = useTabStill(column.tabId);
|
||||||
const [menu, setMenu] = useState<null | { kind: 'filters' | 'menu'; anchor: DOMRect }>(null);
|
const [menu, setMenu] = useState<null | { kind: 'filters' | 'menu'; anchor: DOMRect }>(null);
|
||||||
const [leaving, setLeaving] = useState(false);
|
const [leaving, setLeaving] = useState(false);
|
||||||
|
// Find in page for this column (Ctrl+F pressed in it): the find bar lies over the column's header.
|
||||||
|
const [finding, setFinding] = useState(false);
|
||||||
|
useEffect(() => {
|
||||||
|
const openFindBar = (event: Event) => { if ((event as CustomEvent<string>).detail === column.tabId) setFinding(true); };
|
||||||
|
window.addEventListener('bt-find', openFindBar);
|
||||||
|
return () => window.removeEventListener('bt-find', openFindBar);
|
||||||
|
}, [column.tabId]);
|
||||||
const spec = deckSite();
|
const spec = deckSite();
|
||||||
const runtime = decks.runtime.get(column.tabId);
|
const runtime = decks.runtime.get(column.tabId);
|
||||||
const account = tabProfile(profiles, column.profile);
|
const account = tabProfile(profiles, column.profile);
|
||||||
|
|
@ -236,6 +244,7 @@ function ColumnView({ deck, column, x, width, focused, number }: { deck: Deck; c
|
||||||
<svg className="bt-glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 12h.01M12 12h.01M18 12h.01" strokeWidth="3"/></svg></button>
|
<svg className="bt-glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 12h.01M12 12h.01M18 12h.01" strokeWidth="3"/></svg></button>
|
||||||
{number <= 9 && <span className="bt-col-key" aria-hidden="true">{number}</span>}
|
{number <= 9 && <span className="bt-col-key" aria-hidden="true">{number}</span>}
|
||||||
{runtime?.loading && <span className="bt-col-progress" aria-label={tr('wb.common.loading')}/>}
|
{runtime?.loading && <span className="bt-col-progress" aria-label={tr('wb.common.loading')}/>}
|
||||||
|
{finding && <div className="bt-col-find"><FindBar tabId={column.tabId} url={runtime?.url ?? source ?? ''} onClose={() => setFinding(false)}/></div>}
|
||||||
</header>
|
</header>
|
||||||
<div className="bt-col-body" ref={body}>
|
<div className="bt-col-body" ref={body}>
|
||||||
{still
|
{still
|
||||||
|
|
|
||||||
|
|
@ -288,6 +288,16 @@ function runShortcut(shortcut: string, id?: string) {
|
||||||
if (deckId) runDeckCommand(deckId, shortcut);
|
if (deckId) runDeckCommand(deckId, shortcut);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Find in page in a deck column: that column's own find bar (the keys were pressed in it, or it is the
|
||||||
|
// focused column of the deck in front).
|
||||||
|
if (shortcut === 'find' || shortcut === 'find-next' || shortcut === 'find-previous') {
|
||||||
|
const column = id && !api.getPanel(id) ? id : id === undefined && (api.activePanel?.params as TabParams | undefined)?.kind === 'deck' ? zoomTarget() : null;
|
||||||
|
if (column && findColumnTab(column)?.column) {
|
||||||
|
if (shortcut !== 'find') stepFind(column, shortcut === 'find-next' ? 1 : -1);
|
||||||
|
else if (hasFeature('find')) openFind(column);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
// A browser shortcut pressed inside a deck column acts on its deck tab.
|
// A browser shortcut pressed inside a deck column acts on its deck tab.
|
||||||
if (id && !api.getPanel(id) && findColumnTab(id)) id = deckPanelId(findColumnTab(id)!.deck.id);
|
if (id && !api.getPanel(id) && findColumnTab(id)) id = deckPanelId(findColumnTab(id)!.deck.id);
|
||||||
const panel = id === undefined ? api.activePanel : api.getPanel(id);
|
const panel = id === undefined ? api.activePanel : api.getPanel(id);
|
||||||
|
|
|
||||||
|
|
@ -8,3 +8,7 @@
|
||||||
.bt-find .bt-omni-action:disabled { color: var(--bt-faint); opacity: .6; cursor: default; background: transparent; }
|
.bt-find .bt-omni-action:disabled { color: var(--bt-faint); opacity: .6; cursor: default; background: transparent; }
|
||||||
.bt-shell .bt-find .bt-omni-action svg { width: 15px; height: 15px; }
|
.bt-shell .bt-find .bt-omni-action svg { width: 15px; height: 15px; }
|
||||||
.bt-shell .bt-find .bt-find-up { transform: rotate(180deg); }
|
.bt-shell .bt-find .bt-find-up { transform: rotate(180deg); }
|
||||||
|
|
||||||
|
/* In a deck column the bar lies over the column's header (DeckView.tsx): same field, the column's width. */
|
||||||
|
.bt-col-find { position: absolute; inset: 0; z-index: 3; border-radius: inherit; display: flex; align-items: center; padding-inline: 8px; background: var(--bt-chrome); }
|
||||||
|
.bt-col-find .bt-find { flex: 1; min-width: 0; height: 32px; }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue