feat(web): reopen closed tabs across the app (#15207)

Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
Bilal BakrandJulius Marminge authored and GitHub committed 2026-10-06 12:16:21 -07:00
1 parent 29366ea29a
commit b83d731cab
27 files changed
+1849 -150

No files matched your search

+2
View File
@@ -13,6 +13,7 @@ import { AdvertisedEndpoint } from "./remoteAccess.ts";
import { ExecutionEnvironmentDescriptor } from "./environment.ts";
import { type ClientSettings, type QuitConfirmationMode, SnapShotShortcut } from "./settings.ts";
import type { EditorId } from "./editor.ts";
import type { PreviewForwardedShortcut } from "./keybindings.ts";
import type {
DesktopAppActivationRequest,
@@ -1226,6 +1227,7 @@ export interface DesktopBridge {
export const DESKTOP_PREVIEW_RECORDING_CAPTURE_TRIGGER = "__t3DesktopPreviewRecordingCapture";
export interface DesktopPreviewBridge {
setForwardedShortcuts?: (shortcuts: ReadonlyArray<PreviewForwardedShortcut>) => Promise<void>;
createTab: (tabId: string, defaults?: DesktopPreviewTabDefaults) => Promise<void>;
closeTab: (tabId: string) => Promise<void>;
registerWebview: (tabId: string, webContentsId: number) => Promise<void>;
+7
View File
@@ -69,6 +69,7 @@ export const STATIC_KEYBINDING_COMMANDS = [
"threadPanel.toggle",
"rightPanel.toggleMaximized",
"rightPanel.close",
"view.reopenClosed",
"pullRequest.copyNumber",
"diff.toggle",
"preview.toggle",
@@ -156,6 +157,12 @@ export const KeybindingShortcut = Schema.Struct({
});
export type KeybindingShortcut = typeof KeybindingShortcut.Type;
export const PreviewForwardedShortcut = Schema.Struct({
command: KeybindingCommand,
shortcut: KeybindingShortcut,
});
export type PreviewForwardedShortcut = typeof PreviewForwardedShortcut.Type;
const KeybindingWhenNodeRef = Schema.suspend(
(): Schema.Codec<KeybindingWhenNode> => KeybindingWhenNode,
);
+103
View File
@@ -10,6 +10,108 @@ import {
THREAD_JUMP_KEYBINDING_COMMANDS,
} from "@t3tools/contracts";
export interface ShortcutEventLike {
getModifierState?: (key: "AltGraph") => boolean;
type?: string;
code?: string;
key: string;
repeat?: boolean;
metaKey: boolean;
ctrlKey: boolean;
shiftKey: boolean;
altKey: boolean;
}
export interface ShortcutModifierStateLike {
metaKey: boolean;
ctrlKey: boolean;
shiftKey: boolean;
altKey: boolean;
}
const EVENT_CODE_SHORTCUT_KEYS: Readonly<Record<string, string>> = {
Backquote: "`",
Backslash: "\\",
BracketLeft: "[",
BracketRight: "]",
Comma: ",",
Digit0: "0",
Digit1: "1",
Digit2: "2",
Digit3: "3",
Digit4: "4",
Digit5: "5",
Digit6: "6",
Digit7: "7",
Digit8: "8",
Digit9: "9",
Equal: "=",
Minus: "-",
Period: ".",
Quote: "'",
Semicolon: ";",
Slash: "/",
};
export function isMacPlatform(platform: string): boolean {
return /mac|iphone|ipad|ipod/i.test(platform);
}
export function normalizeEventKey(key: string): string {
const normalized = key.toLowerCase();
if (normalized === "esc") return "escape";
return normalized;
}
export function shortcutKeyFromEvent(event: Pick<ShortcutEventLike, "key" | "code">): string {
const layoutKey = normalizeEventKey(event.key);
if (/^[a-z]$/.test(layoutKey)) return layoutKey;
const physicalKey = event.code ? EVENT_CODE_SHORTCUT_KEYS[event.code] : undefined;
return physicalKey ?? layoutKey;
}
export function resolveEventKeys(event: ShortcutEventLike): Set<string> {
const layoutKey = normalizeEventKey(event.key);
const keys = new Set([layoutKey]);
const letterCode = event.code?.match(/^Key([A-Z])$/)?.[1];
if (letterCode && !/^[a-z]$/.test(layoutKey)) {
keys.add(letterCode.toLowerCase());
}
keys.add(shortcutKeyFromEvent(event));
return keys;
}
export function matchesKeybindingShortcutModifiers(
event: ShortcutModifierStateLike,
shortcut: KeybindingShortcut,
platform: string,
): boolean {
const useMetaForMod = isMacPlatform(platform);
const expectedMeta = shortcut.metaKey || (shortcut.modKey && useMetaForMod);
const expectedCtrl = shortcut.ctrlKey || (shortcut.modKey && !useMetaForMod);
return (
event.metaKey === expectedMeta &&
event.ctrlKey === expectedCtrl &&
event.shiftKey === shortcut.shiftKey &&
event.altKey === shortcut.altKey
);
}
export function matchesKeybindingShortcut(
event: ShortcutEventLike,
shortcut: KeybindingShortcut,
platform: string,
): boolean {
if (
!isMacPlatform(platform) &&
event.getModifierState?.("AltGraph") &&
!/^[a-z0-9]$/i.test(event.key)
)
return false;
if (!matchesKeybindingShortcutModifiers(event, shortcut, platform)) return false;
return resolveEventKeys(event).has(shortcut.key);
}
type WhenToken =
| { type: "identifier"; value: string }
| { type: "not" }
@@ -29,6 +131,7 @@ export const DEFAULT_KEYBINDINGS: ReadonlyArray<KeybindingRule> = [
{ key: "mod+n", command: "terminal.new", when: "terminalFocus" },
{ key: "mod+w", command: "terminal.close", when: "terminalFocus" },
{ key: "mod+w", command: "rightPanel.close", when: "!terminalFocus" },
{ key: "mod+shift+t", command: "view.reopenClosed" },
{ key: "mod+d", command: "diff.toggle", when: "!terminalFocus" },
{ key: "mod+shift+j", command: "preview.toggle" },
{ key: "mod+r", command: "preview.refresh", when: "previewFocus" },