Skip to content

Commit 96037b5

Browse files
authored
Added KeyboardShortcut component for consistent key display (#190)
* Updated user manual and themes marketplace documentation * Added KeyboardShortcut component for consistent key display * Removed unnecessary state for isMac
1 parent 59abc3a commit 96037b5

File tree

13 files changed

+111
-36
lines changed

13 files changed

+111
-36
lines changed

components/KeyboardShortcut.tsx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"use client";
2+
3+
import React, { useEffect, useState } from "react";
4+
5+
interface KeyboardShortcutProps {
6+
shortcut: string;
7+
macosShortcut?: string;
8+
className?: string;
9+
}
10+
11+
const KeyboardShortcut: React.FC<KeyboardShortcutProps> = ({
12+
shortcut,
13+
macosShortcut,
14+
className,
15+
}) => {
16+
const [displayShortcut, setDisplayShortcut] = useState(shortcut);
17+
18+
useEffect(() => {
19+
// OS detection should run only on the client-side
20+
const isMacUser = navigator.platform.toUpperCase().indexOf("MAC") >= 0;
21+
22+
if (isMacUser) {
23+
if (macosShortcut) {
24+
setDisplayShortcut(macosShortcut);
25+
} else {
26+
// Convert common Windows/Linux keys to macOS equivalents
27+
let convertedShortcut = shortcut;
28+
convertedShortcut = convertedShortcut.replace(/Ctrl\s*\+\s*/gi, "⌘ + ");
29+
convertedShortcut = convertedShortcut.replace(/Alt\s*\+\s*/gi, "⌥ + ");
30+
convertedShortcut = convertedShortcut.replace(/Cmd\s*\+\s*/gi, "⌘ + "); // In case Cmd was used in the base shortcut
31+
convertedShortcut = convertedShortcut.replace(
32+
/Option\s*\+\s*/gi,
33+
"⌥ + "
34+
); // In case Option was used
35+
// Replace individual keys if not part of a combo already handled
36+
convertedShortcut = convertedShortcut.replace(/(?<! )Ctrl/gi, "⌘");
37+
convertedShortcut = convertedShortcut.replace(/(?<! )Alt/gi, "⌥");
38+
setDisplayShortcut(convertedShortcut);
39+
}
40+
} else {
41+
// For non-Mac users, display the original shortcut or Windows/Linux specific if ever needed
42+
setDisplayShortcut(shortcut);
43+
}
44+
}, [shortcut, macosShortcut]);
45+
46+
const keys = displayShortcut.split(/\s*\+\s*/);
47+
48+
return (
49+
<span className={`inline-flex items-center ${className || ""}`}>
50+
{keys.map((key, index) => (
51+
<React.Fragment key={index}>
52+
<kbd className="px-1 py-0.5 text-xs font-semibold text-fd-foreground bg-fd-card border border-fd-border rounded-sm">
53+
{key.toLowerCase() === "shift" ? "⇧" : key}
54+
</kbd>
55+
{index < keys.length - 1 && <span className="mx-1">+</span>}
56+
</React.Fragment>
57+
))}
58+
</span>
59+
);
60+
};
61+
62+
export default KeyboardShortcut;

content/docs/contribute/docs/editing-with-vscode.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: Editing with VS Code
33
description: How to use Visual Studio Code to contribute to the Zen Browser documentation.
44
---
5+
import KeyboardShortcut from '@components/KeyboardShortcut';
56

67
Visual Studio Code (VS Code) is a popular and powerful code editor that works well for editing Zen Browser documentation, especially with the right extensions.
78

@@ -27,7 +28,7 @@ To get the best experience editing `.mdx` files in VS Code, we recommend install
2728
### Installation
2829

2930
1. Open VS Code.
30-
2. Go to the Extensions view by clicking the Extensions icon in the Activity Bar on the side of the window or by pressing `Ctrl+Shift+X` (Windows/Linux) or `Cmd+Shift+X` (macOS).
31+
2. Go to the Extensions view by clicking the Extensions icon in the Activity Bar on the side of the window or by pressing <KeyboardShortcut shortcut="Ctrl + Shift + X" />.
3132
3. Search for `mdx`.
3233
4. Click **Install** on the MDX extension by unifiedjs.
3334

content/docs/faq.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: FAQ
33
icon: CircleHelp
44
---
5-
5+
import KeyboardShortcut from '@components/KeyboardShortcut';
66
import { Callout } from 'fumadocs-ui/components/callout';
77
import { InlineTOC } from 'fumadocs-ui/components/inline-toc';
88

@@ -70,7 +70,7 @@ Your support helps the team maintain and enhance Zen Browser for everyone!
7070
Use shortcuts to perform Split View actions faster!
7171
</Callout>
7272

73-
1. Select multiple tabs by left-clicking them while holding the `Ctrl` key, or left-click 2 tabs while holding the `Shift` key to select all tabs in between
73+
1. Select multiple tabs by left-clicking them while holding the <KeyboardShortcut shortcut="Ctrl" /> key, or left-click 2 tabs while holding the <KeyboardShortcut shortcut="Shift" /> key to select all tabs in between
7474
2. Right click a tab, and select `Split x Tabs`
7575
3. Change the view mode by pressing the `[|]` button in the top address bar
7676

content/docs/guides/live-editing.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: Live Editing Zen Theme
33
description: Learn how to live edit the appearance of Zen Browser by editing the userChrome.css file.
44
---
5+
import KeyboardShortcut from '@components/KeyboardShortcut';
56

67
import { Callout } from 'fumadocs-ui/components/callout';
78

@@ -34,7 +35,7 @@ This Guide will help you customize the appearance of Zen Browser by live editing
3435
3. Search for `devtools.chrome.enabled` and toggle it to `true`.
3536
</Callout>
3637

37-
1. In Zen Browser, press `Ctrl + Shift + Alt + I` to open the Developer Tools.
38+
1. In Zen Browser, press <KeyboardShortcut shortcut="Ctrl + Shift + Alt + I" /> to open the Developer Tools.
3839
2. Navigate to the **Style Editor** tab.
3940
3. In the filter/search bar, type `userChrome` to locate the `userChrome.css` file you created earlier.
4041

@@ -52,7 +53,7 @@ This Guide will help you customize the appearance of Zen Browser by live editing
5253
2. You can start editing the file directly within the Style Editor.
5354
![inspect button](/assets/live-editing/inspect.png)
5455
- **Note:** You can use the **Inspect** button to hover over and select elements on the page. This allows you to learn about the `id`, `class`, or other attributes of elements, which you can then target in your `userChrome.css` file.
55-
3. To apply your changes, save the file by clicking **Save** or by pressing `Ctrl + S`.
56+
3. To apply your changes, save the file by clicking **Save** or by pressing <KeyboardShortcut shortcut="Ctrl + S" />.
5657

5758
Any changes you make to the `userChrome.css` file will be applied immediately to Zen Browser.
5859
Use this file to customize various UI elements, such as colors, fonts, and the layout.

content/docs/themes-store/themes-marketplace-preferences.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ You can also have negative conditions
244244

245245
<Callout type="warn" title="Attention">
246246
`property` fields defined in `preferences.json` using the `"dropdown"` type will have one key difference when used in your mod's CSS: <strong>dots (`.`) in the `property` name are replaced with hyphens (`-`)</strong>.
247-
<br/><br/>
247+
248248
E.g. `mod.mymod.background_color` becomes `mod-mymod-background_color` in the CSS file.
249249
This transformation ensures that the property can be used as an attribute selector or inside a media query.
250250
</Callout>
@@ -358,7 +358,7 @@ String preferences can be detected in your CSS using the `var(--property)` opera
358358

359359
<Callout type="warn" title="Attention">
360360
`property` fields defined in `preferences.json` using the `"string"` type will have one key difference when used in your mod's CSS: <strong>dots (`.`) in the `property` name are replaced with hyphens (`-`)</strong>.
361-
<br/><br/>
361+
362362
E.g. `mod.mymod.background_color` becomes `mod-mymod-background_color` in the CSS file.
363363
This transformation ensures that the property can be used as an attribute selector or inside a media query.
364364
</Callout>

content/docs/user-manual/bookmarks.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title: Bookmarks
33
description: Managing bookmarks in Zen
44
---
55
import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
6+
import KeyboardShortcut from '@components/KeyboardShortcut';
67

78
Zen, as a fork of Firefox, inherits its webpage bookmarking system primarily from Firefox itself, with some additional Zen enhancements. Zen offers two vertical tab layouts: **Single toolbar layout**, which integrates a compact address bar into the vertical tabs toolbar, and **Multiple toolbars layout**, featuring a traditional, full-size address bar in a separate horizontal toolbar. This guide covers the basics of creating and managing bookmarks, tailored to your chosen Zen layout.
89

@@ -29,7 +30,7 @@ To bookmark a page, find and click on the bookmark icon in the address bar. A po
2930

3031

3132
<Callout type="info" title="Tips:">
32-
While you could use your mouse to click the bookmark icon, we recommend using the keyboard shortcut `Ctrl/Cmd + D` for bookmarking, especially in **Single toolbar layout**.
33+
While you could use your mouse to click the bookmark icon, we recommend using the keyboard shortcut <KeyboardShortcut shortcut="Ctrl + D" /> for bookmarking, especially in **Single toolbar layout**.
3334
</Callout>
3435

3536
Alternatively, you can bookmark a single tab by right-clicking it and selecting `"Bookmark Tab..."` from the context menu, which opens a detailed bookmarking dialog with options for *tagging* and *keywords*.
@@ -47,7 +48,7 @@ You can find your recently added bookmarks through Zen's application menu. Click
4748
### Bookmarks Toolbar and Bookmarks Menu
4849

4950
Taken from the default behavior of Gecko, Zen offers 3 locations (or, groups) for bookmarks:
50-
- **Bookmarks Toolbar**: This can be considered a public location for bookmarks, displayed in the browser's [chrome](https://developer.mozilla.org/en-US/docs/Glossary/Chrome). You typically find it beneath the main browser toolbar, which is featured in **Multiple toolbars layout** in Zen, while in **Single toolbar layout**, hovering your cursor to the top edge will display the hidden Bookmarks Toolbar, next to your window controls. To toggle the visibility of your Bookmarks Toolbar, use the shortcut `Ctrl/Cmd + Shift + B`
51+
- **Bookmarks Toolbar**: This can be considered a public location for bookmarks, displayed in the browser's [chrome](https://developer.mozilla.org/en-US/docs/Glossary/Chrome). You typically find it beneath the main browser toolbar, which is featured in **Multiple toolbars layout** in Zen, while in **Single toolbar layout**, hovering your cursor to the top edge will display the hidden Bookmarks Toolbar, next to your window controls. To toggle the visibility of your Bookmarks Toolbar, use the shortcut <KeyboardShortcut shortcut="Ctrl + Shift + B" />
5152

5253
{/* TODO: *insert video* */}
5354
![Bookmarks Toolbar](/assets/user-manual/bookmarks/bookmarks-toolbar.png)
@@ -64,14 +65,14 @@ Taken from the default behavior of Gecko, Zen offers 3 locations (or, groups) fo
6465

6566
### Bookmarks Sidebar
6667

67-
Your bookmarks are also available via what is known as the [Firefox Sidebar](https://support.mozilla.org/kb/use-firefox-sidebar-access-bookmarks-history-synced). The Sidebar can be opened by adding a Sidebar button to your controls, or preferably by using the shortcut `Ctr/Cmd + B` to open the Bookmarks Sidebar. You can find all of your bookmarks here including entries from both Bookmarks Toolbar and Bookmarks Menu, in the form of a tree structure explorer with access to a searching function at the top.
68+
Your bookmarks are also available via what is known as the [Firefox Sidebar](https://support.mozilla.org/kb/use-firefox-sidebar-access-bookmarks-history-synced). The Sidebar can be opened by adding a Sidebar button to your controls, or preferably by using the shortcut <KeyboardShortcut shortcut="Ctrl + B" /> to open the Bookmarks Sidebar. You can find all of your bookmarks here including entries from both Bookmarks Toolbar and Bookmarks Menu, in the form of a tree structure explorer with access to a searching function at the top.
6869

6970
{/* TODO: *insert video/image* */}
7071
![Bookmarks Sidebar](/assets/user-manual/bookmarks/bookmarks-sidebar.png)
7172

7273
### Bookmarks Library
7374

74-
The Firefox Library is a unified manager for Bookmarks, History, and Downloads. You can access the Library by the shortcut `Ctrl/Cmd + Shift + O` or from the application menu `"Bookmarks"`>`"Manage bookmarks"`. While most of its functions here have already been offered via the Bookmarks Sidebar, the Library is important for your purpose of Importing and Backing up Zen's bookmarks.
75+
The Firefox Library is a unified manager for Bookmarks, History, and Downloads. You can access the Library by the shortcut <KeyboardShortcut shortcut="Ctrl + Shift + O" /> or from the application menu `"Bookmarks"`>`"Manage bookmarks"`. While most of its functions here have already been offered via the Bookmarks Sidebar, the Library is important for your purpose of Importing and Backing up Zen's bookmarks.
7576

7677
![Bookmarks Library](/assets/user-manual/bookmarks/bookmarks-library.png)
7778

content/docs/user-manual/compact-mode.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
title: Compact Mode
33
description: Minimalistic interface for focused browsing
44
---
5+
import KeyboardShortcut from '@components/KeyboardShortcut';
56

67
Compact Mode is one of Zen's main feature that let you hide all browser toolbars and give wider view for the website you're currently visit.
78

8-
You can activate this feature by right click on empty area on the `toolbar > "Compact Mode" > "Enable compact mode"`, or use `Alt + Ctrl/Cmd + C` keyboard shortcut.
9+
You can activate this feature by right click on empty area on the `toolbar > "Compact Mode" > "Enable compact mode"`, or use <KeyboardShortcut shortcut="Alt + Ctrl + C" /> keyboard shortcut.
910

1011
{
1112
<div align="center">
@@ -28,8 +29,8 @@ In Multiple Toolbar or Collapsed Toolbar mode, you can choose which bar to hide.
2829

2930
You can also use these extra shortcuts to show the hidden bars, suitable for heavy keyboard users. Unlike usual hovering gesture, showing sidebar/toolbar using these shortcuts is done persistently, until you pressed the shortcut again to hide it.
3031

31-
- **Toggle Floating Sidebar**: `Alt + Ctrl/Cmd + S` - Show the tab sidebar for all toolbar modes
32-
- **Toggle Floating Toolbar**: `Alt + Ctrl/Cmd + W` - Show the top toolbar for Multiple & Collapsed Toolbar mode
32+
- **Toggle Floating Sidebar**: <KeyboardShortcut shortcut="Alt + Ctrl + S" /> - Show the tab sidebar for all toolbar modes
33+
- **Toggle Floating Toolbar**: <KeyboardShortcut shortcut="Alt + Ctrl + W" /> - Show the top toolbar for Multiple & Collapsed Toolbar mode
3334

3435
<Callout>
3536
_All shortcuts can be modified via `Settings > Keyboard Shortcuts`._

content/docs/user-manual/extensions.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: Extensions
33
description: Get to know how extensions work in Zen
44
---
5+
import KeyboardShortcut from '@components/KeyboardShortcut';
56

67
Extensions are a small software piece that enhance and personalize a browser by adding or modifying browser function and features. Example of commonly installed extensions includes ad blockers, easy reader mode, privacy and tracking managers, media downloaders, password managers, and tweaks for commonly used websites.
78

@@ -25,7 +26,7 @@ If you haven't installed any extensions yet, clicking the Extensions button will
2526
Add-Ons Manager is a page that primarily let you see extension details, manage its preferences, assign shortcuts, disable and remove extensions. You can access Add-Ons Manager by:
2627
- Open the extension button > Click `Manage extensions`.
2728
- Open the main menu > Click "Add-ons and themes".
28-
- Press the default keyboard shortcut `Ctrl/Cmd + Shift + A`.
29+
- Press the default keyboard shortcut <KeyboardShortcut shortcut="Ctrl + Shift + A" />.
2930

3031
Select "Extensions" and you can see the list of your installed extensions. You can click on each extensions name to expand the details, or click toggle in each extensions to disable or enable it.
3132

content/docs/user-manual/glance.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
title: Glance
33
description: Preview websites on top of your current tab
44
---
5+
import KeyboardShortcut from '@components/KeyboardShortcut';
56

6-
Zen's Glance lets you preview websites on top of your current tab, without fully switching to it. By default, you can create a Glance view by holding `Alt` as trigger key when clicking a link in a regular tab. In Essentials and pinned tabs, Glance will be automatically created when clicking a link outside current website, without having to pressing the trigger key.
7+
Zen's Glance lets you preview websites on top of your current tab, without fully switching to it. By default, you can create a Glance view by holding <KeyboardShortcut shortcut="Alt" /> as trigger key when clicking a link in a regular tab. In Essentials and pinned tabs, Glance will be automatically created when clicking a link outside current website, without having to pressing the trigger key.
78

89
{
910
<div align="center">
@@ -20,6 +21,6 @@ Once Glance appeared, there's three buttons on its top left side:
2021
- Expand button to move the website into a new tab.
2122
- Split button to add the website as a split tab.
2223

23-
You can disable/enable Glance and change the trigger method (from `Alt + Click` to `Ctrl + Click` or `Shift + Click`) by opening `Settings` > `Look and Feel` > `Glance`.
24+
You can disable/enable Glance and change the trigger method (from <KeyboardShortcut shortcut="Alt + Click" /> to <KeyboardShortcut shortcut="Ctrl + Click" /> or <KeyboardShortcut shortcut="Shift + Click" />) by opening `Settings` > `Look and Feel` > `Glance`.
2425

2526
With Glance, you can take a quick look of websites, move on if you're done with the site, and go back to your previous surfing activities easily.

content/docs/user-manual/pip.mdx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: Picture-in-Picture
33
description: Watch videos in a separate window
44
---
5+
import KeyboardShortcut from '@components/KeyboardShortcut';
56

67
With **Picture-in-Picture (PiP)** in **Zen**, you can pop videos out of webpages into a clean, always-on-top floating window. Whether you're working, browsing, or just casually scrolling, PiP keeps your video visible without disrupting your flow.
78

@@ -30,7 +31,7 @@ On pages with a single video, Zen displays a PiP icon in the **address bar**.
3031
You can also launch PiP by **right-clicking** on the video.
3132

3233
- Some platforms like YouTube use custom menus.
33-
In that case, use **Shift + Right-Click** or **double right-click** to access Zen’s native menu.
34+
In that case, use <KeyboardShortcut shortcut="Shift + Right-Click" /> or **double right-click** to access Zen’s native menu.
3435

3536
![PIP context menu](/assets/user-manual/pip/pip-context-menu.png)
3637

@@ -45,17 +46,17 @@ Enable it by setting the property below in about:config to TRUE
4546

4647
## Keyboard Shortcuts
4748

48-
| Action | Shortcut |
49-
|------------------------------|-----------------------------|
50-
| Launch/Close PiP | `Ctrl + Shift + ]` |
51-
| Mute / Unmute | `Ctrl + ↓ / Ctrl + ↑` |
52-
| Volume Control | `↑ / ↓` |
53-
| Seek 5s Back / Forward | `← / →` |
54-
| Seek 10% Back / Forward | `Ctrl + ← / Ctrl + →` |
55-
| Jump to Start / End | `Home / End` |
56-
| Pause / Play | `Space` |
57-
| Fullscreen Toggle | `Double-click` or `F` |
58-
| Close PiP Window | `Ctrl + W` |
49+
| Action | Shortcut |
50+
|------------------------------|-------------------------------------------------------------------------------------------|
51+
| Launch/Close PiP | <KeyboardShortcut shortcut="Ctrl + Shift + ]" /> |
52+
| Mute / Unmute | <KeyboardShortcut shortcut="Ctrl + ↓" /> / <KeyboardShortcut shortcut="Ctrl + ↑" /> |
53+
| Volume Control | <KeyboardShortcut shortcut="" /> / <KeyboardShortcut shortcut="" /> |
54+
| Seek 5s Back / Forward | <KeyboardShortcut shortcut="" /> / <KeyboardShortcut shortcut="" /> |
55+
| Seek 10% Back / Forward | <KeyboardShortcut shortcut="Ctrl + ←" /> / <KeyboardShortcut shortcut="Ctrl + →" /> |
56+
| Jump to Start / End | <KeyboardShortcut shortcut="Home" /> / <KeyboardShortcut shortcut="End" /> |
57+
| Pause / Play | <KeyboardShortcut shortcut="Space" /> |
58+
| Fullscreen Toggle | <KeyboardShortcut shortcut="Double-click" /> or <KeyboardShortcut shortcut="F" /> |
59+
| Close PiP Window | <KeyboardShortcut shortcut="Ctrl + W" /> |
5960

6061

6162
## How to Disable Picture-in-Picture
@@ -138,4 +139,5 @@ More platforms are being added.
138139
- **Simple Dismissal**
139140
To hide the Media Player, just click the “X” on the controller. Zen will take the hint.
140141

141-
{/* TODO: enter video */}
142+
{/* TODO: enter video */}
143+

0 commit comments

Comments
 (0)