Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion content/docs/user-manual/pip.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Enable it by setting the property below in about:config to TRUE

| Action | Shortcut |
|------------------------------|-------------------------------------------------------------------------------------------|
| Launch/Close PiP | <KeyboardShortcut shortcut="Ctrl + Shift + ]" /> |
| Launch/Close PiP | <KeyboardShortcut shortcut="Ctrl + Shift + ]" rewriteCtrlToCmd={false} /> |
| Mute / Unmute | <KeyboardShortcut shortcut="Ctrl + ↓" /> / <KeyboardShortcut shortcut="Ctrl + ↑" /> |
| Volume Control | <KeyboardShortcut shortcut="↑" /> / <KeyboardShortcut shortcut="↓" /> |
| Seek 5s Back / Forward | <KeyboardShortcut shortcut="←" /> / <KeyboardShortcut shortcut="→" /> |
Expand Down
28 changes: 14 additions & 14 deletions content/docs/user-manual/shortcuts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The "Toggle Split View" shortcuts currently only applicable when selecting multi

| **Action** | **Shortcut** |
| ----------------------- | ------------------------------------------------ |
| New Window | <KeyboardShortcut shortcut="Crtl + N" /> |
| New Window | <KeyboardShortcut shortcut="Ctrl + N" /> |
| New Tab | <KeyboardShortcut shortcut="Ctrl + T" /> |
| Close Tab | <KeyboardShortcut shortcut="Ctrl + W" /> |
| Close Window | <KeyboardShortcut shortcut="Shift + Ctrl + W" /> |
Expand All @@ -72,18 +72,18 @@ The "Toggle Split View" shortcuts currently only applicable when selecting multi
- When you're in Compact Mode and switching tabs using <KeyboardShortcut shortcut="Ctrl + Tab" /> or <KeyboardShortcut shortcut="Ctrl + Shift + Tab" />, you can peek into the tab you're switching in by enabling the **"Briefly make the toolbar popup when switching or opening new tabs in compact mode"** option in `Settings` > `Look and Feel` > `Theme Settings`.
- Pressing <KeyboardShortcut shortcut="Ctrl + Tab" /> when you're in the last tab will switch you to the first available tab (Essentials first, then pinned tabs, and lastly, regular tabs).
- ^ Tab numbers listed for these keyboard shortcuts includes Essentials and pinned tabs. Example: If you have three Essentials, four pinned tabs, and five regular tabs:
- <KeyboardShortcut shortcut="Alt + 1" /> until <KeyboardShortcut shortcut="Alt + 3" /> will switch you to your Essentials,
- <KeyboardShortcut shortcut="Alt + 4" /> until <KeyboardShortcut shortcut="Alt + 7" /> will switch you to your pinned tabs,
- <KeyboardShortcut shortcut="Alt + 8" /> will switch you to your first regular tab,
- <KeyboardShortcut shortcut="Alt + 9" /> will switch you to your last tab (12th).
- Zen can also let you cycle through recently used tabs, instead of cycling through all of your tabs. Enable it by go to `Settings` > `General` > `Tabs` and check the `Ctrl + Tab cycles through tabs in recently used order`. A popup containing up to 7 recently used tabs will show up when you press <KeyboardShortcut shortcut="Ctrl + Tab" />.
- <KeyboardShortcut shortcut="Alt + 1" macosShortcut="Cmd + 1" /> until <KeyboardShortcut shortcut="Alt + 3" macosShortcut="Cmd + 3" /> will switch you to your Essentials,
- <KeyboardShortcut shortcut="Alt + 4" macosShortcut="Cmd + 4" /> until <KeyboardShortcut shortcut="Alt + 7" macosShortcut="Cmd + 7" /> will switch you to your pinned tabs,
- <KeyboardShortcut shortcut="Alt + 8" macosShortcut="Cmd + 8" /> will switch you to your first regular tab,
- <KeyboardShortcut shortcut="Alt + 9" macosShortcut="Cmd + 9" /> will switch you to your last tab (12th).
- Zen can also let you cycle through recently used tabs, instead of cycling through all of your tabs. Enable it by go to `Settings` > `General` > `Tabs` and check the `Ctrl + Tab cycles through tabs in recently used order`. A popup containing up to 7 recently used tabs will show up when you press <KeyboardShortcut shortcut="Ctrl + Tab" rewriteCtrlToCmd={false} />.

### Navigation

| **Action** | **Shortcut** |
| ------------------------------------ | ------------------------------------------------ |
| Go Back | <KeyboardShortcut shortcut="Alt + ←" /> |
| Go Forward | <KeyboardShortcut shortcut="Alt + →" /> |
| Go Back | <KeyboardShortcut shortcut="Alt + ←" macosShortcut="Cmd + ←" /> |
| Go Forward | <KeyboardShortcut shortcut="Alt + →" macosShortcut="Cmd + →" /> |
| Navigate Back (Alternative) | <KeyboardShortcut shortcut="Ctrl + [" /> |
| Navigate Forward (Alternative) | <KeyboardShortcut shortcut="Ctrl + ]" /> |
| Go Home | <KeyboardShortcut shortcut="Alt + Home" /> |
Expand Down Expand Up @@ -141,14 +141,14 @@ The "Toggle Split View" shortcuts currently only applicable when selecting multi

| **Action** | **Shortcut** |
| ----------------------------- | ------------------------------------------------------ |
| Toggle DevTools | <KeyboardShortcut shortcut="Shift + Ctrl + I" /> |
| Toggle DevTools | <KeyboardShortcut shortcut="Shift + Ctrl + I" macosShortcut="Cmd + Alt + I" /> |
| Toggle Browser Toolbox | <KeyboardShortcut shortcut="Alt + Shift + Ctrl + I" /> |
| Toggle Browser Console | <KeyboardShortcut shortcut="Shift + Ctrl + J" /> |
| Toggle Responsive Design Mode | <KeyboardShortcut shortcut="Shift + Ctrl + M" /> |
| Toggle Inspector | <KeyboardShortcut shortcut="Shift + Ctrl + L" /> |
| Toggle Web Console | <KeyboardShortcut shortcut="Shift + Ctrl + K" /> |
| Toggle JavaScript Debugger | <KeyboardShortcut shortcut="Shift + Ctrl + Z" /> |
| Toggle Network Monitor | <KeyboardShortcut shortcut="Shift + Ctrl + E" /> |
| Toggle Responsive Design Mode | <KeyboardShortcut shortcut="Shift + Ctrl + M" macosShortcut="Cmd + Alt + M" /> |
| Toggle Inspector | <KeyboardShortcut shortcut="Shift + Ctrl + L" macosShortcut="Cmd + Alt + L" /> |
| Toggle Web Console | <KeyboardShortcut shortcut="Shift + Ctrl + K" macosShortcut="Cmd + Alt + K" /> |
| Toggle JavaScript Debugger | <KeyboardShortcut shortcut="Shift + Ctrl + Z" macosShortcut="Cmd + Alt + Z" /> |
| Toggle Network Monitor | <KeyboardShortcut shortcut="Shift + Ctrl + E" macosShortcut="Cmd + Alt + E" /> |
| Toggle Style Editor | <KeyboardShortcut shortcut="Shift + F7" /> |
| Toggle Performance | <KeyboardShortcut shortcut="Shift + F5" /> |
| Toggle Storage | <KeyboardShortcut shortcut="Shift + F9" /> |
Expand Down
49 changes: 30 additions & 19 deletions src/components/KeyboardShortcut.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,53 @@ interface KeyboardShortcutProps {
shortcut: string;
macosShortcut?: string;
className?: string;
rewriteCtrlToCmd?: boolean;
}

// OS detection should run only on the client-side
const isMacUser = navigator.platform.toUpperCase().indexOf("MAC") >= 0;

const toCharacter = (shortcut: string): string =>
shortcut
.replace(/Ctrl\s*\+\s*/gi, "⌃ + ")
.replace(/Alt\s*\+\s*/gi, "⌥ + ")
// In case Cmd was used in the base shortcut
.replace(/Cmd\s*\+\s*/gi, "⌘ + ")
// In case Option was used
.replace(/Option\s*\+\s*/gi, "⌥ + ")
// Replace individual keys if not part of a combo already handled
.replace(/(?<!⌘ )Cmd/gi, "⌘")
.replace(/(?<!⌃ )Ctrl/gi, "⌃")
.replace(/(?<!⌥ )Alt/gi, "⌥");

const KeyboardShortcut: React.FC<KeyboardShortcutProps> = ({
shortcut,
macosShortcut,
className,
rewriteCtrlToCmd = true,
}) => {
const [displayShortcut, setDisplayShortcut] = useState(shortcut);

useEffect(() => {
// OS detection should run only on the client-side
const isMacUser = navigator.platform.toUpperCase().indexOf("MAC") >= 0;

if (isMacUser) {
if (macosShortcut) {
setDisplayShortcut(macosShortcut);
setDisplayShortcut(toCharacter(macosShortcut));
} else {
// Convert common Windows/Linux keys to macOS equivalents
let convertedShortcut = shortcut;
convertedShortcut = convertedShortcut.replace(/Ctrl\s*\+\s*/gi, "⌘ + ");
convertedShortcut = convertedShortcut.replace(/Alt\s*\+\s*/gi, "⌥ + ");
convertedShortcut = convertedShortcut.replace(/Cmd\s*\+\s*/gi, "⌘ + "); // In case Cmd was used in the base shortcut
convertedShortcut = convertedShortcut.replace(
/Option\s*\+\s*/gi,
"⌥ + "
); // In case Option was used
// Replace individual keys if not part of a combo already handled
convertedShortcut = convertedShortcut.replace(/(?<!⌘ )Ctrl/gi, "⌘");
convertedShortcut = convertedShortcut.replace(/(?<!⌥ )Alt/gi, "⌥");
setDisplayShortcut(convertedShortcut);
setDisplayShortcut(
toCharacter(
shortcut.replace(
/Ctrl\s*\+\s*/gi,
`${rewriteCtrlToCmd ? "Cmd" : "Ctrl"} + `,
),
),
);
}
} else {
// For non-Mac users, display the original shortcut or Windows/Linux specific if ever needed
setDisplayShortcut(shortcut);
}
}, [shortcut, macosShortcut]);
}, [shortcut, macosShortcut, rewriteCtrlToCmd]);

const keys = displayShortcut.split(/\s*\+\s*/);

Expand All @@ -53,8 +64,8 @@ const KeyboardShortcut: React.FC<KeyboardShortcutProps> = ({
{key.toLowerCase() === "shift"
? "⇧"
: key.toLowerCase() === "plus"
? "+"
: key}
? "+"
: key}
</kbd>
{index < keys.length - 1 && <span className="mx-1">+</span>}
</React.Fragment>
Expand Down