common: support mac keyboard formatting

Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
01zulfi
2025-07-22 09:53:26 +05:00
committed by Abdullah Atta
parent 0185eea740
commit d55a2aa04d
3 changed files with 66 additions and 62 deletions

View File

@@ -9,72 +9,73 @@ The following keyboard shortcuts will help you navigate Notesnook faster.
| Description | Web | Windows/Linux | Mac | | Description | Web | Windows/Linux | Mac |
| --- | --- | --- | --- | | --- | --- | --- | --- |
| Next tab | Ctrl Alt right / Ctrl Alt Shift right | Ctrl tab | Command tab | | Next tab | Ctrl Alt right / ⌘ ⌥ ⇧ right | Ctrl tab | tab |
| Previous tab | Ctrl Alt left / Ctrl Alt Shift left | Ctrl Shift tab | Command Shift tab | | Previous tab | Ctrl Alt left / ⌘ ⌥ ⇧ left | Ctrl tab | ⌘ ⇧ tab |
| New tab | - | Ctrl t | Command t | | New tab | - | Ctrl t | t |
| Close active tab | - | Ctrl w | Command w | | Close active tab | - | Ctrl w | w |
| Close all tabs | - | Ctrl Shift w | Command Shift w | | Close all tabs | - | Ctrl ⇧ w | ⌘ ⇧ w |
| Command palette | Ctrl k | Ctrl k | Command k | | Command palette | Ctrl k | Ctrl k | k |
| Quick open | Ctrl p | Ctrl p | Command p | | Quick open | Ctrl p | Ctrl p | p |
### Note ### Note
| Description | Web | Windows/Linux | Mac | | Description | Web | Windows/Linux | Mac |
| --- | --- | --- | --- | | --- | --- | --- | --- |
| New note | - | Ctrl n | Command n | | New note | - | Ctrl n | n |
### General ### General
| Description | Web | Windows/Linux | Mac | | Description | Web | Windows/Linux | Mac |
| --- | --- | --- | --- | | --- | --- | --- | --- |
| Search in notes list view if editor is not focused | Ctrl f | Ctrl f | Command f | | Search in notes list view if editor is not focused | Ctrl f | Ctrl f | f |
| Settings | Ctrl , | Ctrl , | Command , | | Settings | Ctrl , | Ctrl , | , |
| Keyboard shortcuts | Ctrl / | Ctrl / | Command / | | Keyboard shortcuts | Ctrl / | Ctrl / | / |
### Editor ### Editor
| Description | Web | Windows/Linux | Mac | | Description | Web | Windows/Linux | Mac |
| --- | --- | --- | --- | | --- | --- | --- | --- |
| Add attachment | Ctrl Shift A | Ctrl Shift A | Command Shift A | | Add attachment | Ctrl A | Ctrl ⇧ A | ⌘ ⇧ A |
| Insert blockquote | Ctrl Shift B | Ctrl Shift B | Command Shift B | | Insert blockquote | Ctrl B | Ctrl ⇧ B | ⌘ ⇧ B |
| Toggle bold | Ctrl b | Ctrl b | Command b | | Toggle bold | Ctrl b | Ctrl b | b |
| Toggle bullet list | Ctrl Shift 8 | Ctrl Shift 8 | Command Shift 8 | | Toggle bullet list | Ctrl 8 | Ctrl ⇧ 8 | ⌘ ⇧ 8 |
| Toggle check list | Ctrl Shift 9 | Ctrl Shift 9 | Command Shift 9 | | Toggle check list | Ctrl 9 | Ctrl ⇧ 9 | ⌘ ⇧ 9 |
| Split list item | Enter | Enter | Enter | | Split list item | Enter | Enter | Enter |
| Lift list item | Shift Tab | Shift Tab | Shift Tab | | Lift list item | Tab | Tab | Tab |
| Sink list item | Ctrl Shift Down | Ctrl Shift Down | Command Shift Down | | Sink list item | Ctrl Down | Ctrl Down | ⌘ ⇧ Down |
| Toggle code | Ctrl e | Ctrl e | Command e | | Toggle code | Ctrl e | Ctrl e | e |
| Toggle code block | Ctrl Shift C | Ctrl Shift C | Command Shift C | | Toggle code block | Ctrl C | Ctrl ⇧ C | ⌘ ⇧ C |
| Insert date | Alt d | Alt d | Option d | | Insert date | Alt d | Alt d | Option d |
| Insert time | Alt t | Alt t | Option t | | Insert time | Alt t | Alt t | Option t |
| Insert date and time | Ctrl Alt d | Ctrl Alt d | Command Option d | | Insert date and time | Ctrl Alt d | Ctrl Alt d | Option d |
| Insert date and time with timezone | Ctrl Alt z | Ctrl Alt z | Command Option z | | Insert date and time with timezone | Ctrl Alt z | Ctrl Alt z | Option z |
| Increase font size | Ctrl [ | Ctrl [ | Command [ | | Increase font size | Ctrl [ | Ctrl [ | [ |
| Decrease font size | Ctrl ] | Ctrl ] | Command ] | | Decrease font size | Ctrl ] | Ctrl ] | ] |
| Insert heading 1 | Ctrl Alt 1 | Ctrl Alt 1 | Command Option 1 | | Insert paragraph | Ctrl ⇧ 0 | Ctrl ⇧ 0 | ⌘ ⇧ 0 |
| Insert heading 2 | Ctrl Alt 2 | Ctrl Alt 2 | Command Option 2 | | Insert heading 1 | Ctrl Alt 1 | Ctrl Alt 1 | Option 1 |
| Insert heading 3 | Ctrl Alt 3 | Ctrl Alt 3 | Command Option 3 | | Insert heading 2 | Ctrl Alt 2 | Ctrl Alt 2 | Option 2 |
| Insert heading 4 | Ctrl Alt 4 | Ctrl Alt 4 | Command Option 4 | | Insert heading 3 | Ctrl Alt 3 | Ctrl Alt 3 | Option 3 |
| Insert heading 5 | Ctrl Alt 5 | Ctrl Alt 5 | Command Option 5 | | Insert heading 4 | Ctrl Alt 4 | Ctrl Alt 4 | Option 4 |
| Insert heading 6 | Ctrl Alt 6 | Ctrl Alt 6 | Command Option 6 | | Insert heading 5 | Ctrl Alt 5 | Ctrl Alt 5 | Option 5 |
| Undo | Ctrl z | Ctrl z | Command z | | Insert heading 6 | Ctrl Alt 6 | Ctrl Alt 6 | ⌘ Option 6 |
| Redo | Ctrl Shift z / Ctrl y | Ctrl Shift z / Ctrl y | Command Shift z / Command y | | Undo | Ctrl z | Ctrl z | ⌘ z |
| Add image | Ctrl Shift I | Ctrl Shift I | Command Shift I | | Redo | Ctrl ⇧ z / ⌘ y | Ctrl ⇧ z / ⌘ y | ⌘ ⇧ z / ⌘ y |
| Toggle italic | Ctrl i | Ctrl i | Command i | | Add image | Ctrl ⇧ I | Ctrl ⇧ I | ⌘ ⇧ I |
| Remove formatting in selection | Ctrl \ | Ctrl \ | Command \ | | Toggle italic | Ctrl i | Ctrl i | ⌘ i |
| Insert internal link | Ctrl Shift L | Ctrl Shift L | Command Shift L | | Remove formatting in selection | Ctrl \ | Ctrl \ | ⌘ \ |
| Insert link | Ctrl Shift K | Ctrl Shift K | Command Shift K | | Insert internal link | Ctrl ⇧ L | Ctrl ⇧ L | ⌘ ⇧ L |
| Insert math block | Ctrl Shift M | Ctrl Shift M | Command Shift M | | Insert link | Ctrl ⇧ K | Ctrl ⇧ K | ⌘ ⇧ K |
| Toggle ordered list | Ctrl Shift 7 | Ctrl Shift 7 | Command Shift 7 | | Insert math block | Ctrl ⇧ M | Ctrl ⇧ M | ⌘ ⇧ M |
| Toggle outline list | Ctrl Shift O | Ctrl Shift O | Command Shift O | | Toggle ordered list | Ctrl ⇧ 7 | Ctrl ⇧ 7 | ⌘ ⇧ 7 |
| Toggle outline list expand | Ctrl Space | Ctrl Space | Command Space | | Toggle outline list | Ctrl ⇧ O | Ctrl ⇧ O | ⌘ ⇧ O |
| Open search | Ctrl F | Ctrl F | Command F | | Toggle outline list expand | Ctrl Space | Ctrl Space | ⌘ Space |
| Toggle strike | Ctrl Shift S | Ctrl Shift S | Command Shift S | | Open search | Ctrl F | Ctrl F | ⌘ F |
| Toggle subscript | Ctrl , | Ctrl , | Command , | | Toggle strike | Ctrl ⇧ S | Ctrl ⇧ S | ⌘ ⇧ S |
| Toggle superscript | Ctrl . | Ctrl . | Command . | | Toggle subscript | Ctrl , | Ctrl , | ⌘ , |
| Toggle task list | Ctrl Shift T | Ctrl Shift T | Command Shift T | | Toggle superscript | Ctrl . | Ctrl . | ⌘ . |
| Text align center | Ctrl Shift E | Ctrl Shift E | Command Shift E | | Toggle task list | Ctrl ⇧ T | Ctrl ⇧ T | ⌘ ⇧ T |
| Text align justify | Ctrl Shift J | Ctrl Shift J | Command Shift J | | Text align center | Ctrl ⇧ E | Ctrl ⇧ E | ⌘ ⇧ E |
| Text align left | Ctrl Shift L | Ctrl Shift L | Command Shift L | | Text align justify | Ctrl ⇧ J | Ctrl ⇧ J | ⌘ ⇧ J |
| Text align right | Ctrl Shift R | Ctrl Shift R | Command Shift R | | Text align left | Ctrl ⇧ L | Ctrl ⇧ L | ⌘ ⇧ L |
| Underline | Ctrl u | Ctrl u | Command u | | Text align right | Ctrl ⇧ R | Ctrl ⇧ R | ⌘ ⇧ R |
| Underline | Ctrl u | Ctrl u | ⌘ u |

View File

@@ -45,21 +45,24 @@ function getGroupedTableKeybindingsMarkdown() {
if (!mergedShortcuts[description]) { if (!mergedShortcuts[description]) {
mergedShortcuts[description] = {}; mergedShortcuts[description] = {};
} }
mergedShortcuts[description].web = keys.map(formatKey); mergedShortcuts[description].web = keys;
}); });
desktopShortcuts.forEach(({ description, keys }) => { desktopShortcuts.forEach(({ description, keys }) => {
if (!mergedShortcuts[description]) { if (!mergedShortcuts[description]) {
mergedShortcuts[description] = {}; mergedShortcuts[description] = {};
} }
mergedShortcuts[description].desktop = keys.map(formatKey); mergedShortcuts[description].desktop = keys;
}); });
const rows = Object.entries(mergedShortcuts) const rows = Object.entries(mergedShortcuts)
.map(([description, { web, desktop }]) => { .map(([description, { web, desktop }]) => {
const webKeys = web?.join(" / ") || "-"; const webKeys = web?.map(formatKey).join(" / ") || "-";
const windowsLinuxKeys = desktop?.join(" / ") || "-"; const windowsLinuxKeys = desktop?.map(formatKey).join(" / ") || "-";
const macKeys = const macKeys =
desktop?.map(macify).map(formatKey).join(" / ") || "-"; desktop
?.map(macify)
.map((k) => formatKey(k, true))
.join(" / ") || "-";
return `| ${description} | ${webKeys} | ${windowsLinuxKeys} | ${macKeys} |`; return `| ${description} | ${webKeys} | ${windowsLinuxKeys} | ${macKeys} |`;
}) })

View File

@@ -410,14 +410,14 @@ export function macify(key: string) {
.replace(/mod/gi, "Command"); .replace(/mod/gi, "Command");
} }
export function formatKey(key: string) { export function formatKey(key: string, isMac = false) {
return key return key
.replace(/\+|-/g, " ") .replace(/\+|-/g, " ")
.replace(/\bcommand\b/gi, "Command") .replace(/\bcommand\b/gi, isMac ? "⌘" : "Command")
.replace(/\bctrl\b/gi, "Ctrl") .replace(/\bctrl\b/gi, isMac ? "⌘" : "Ctrl")
.replace(/\bshift\b/gi, "Shift") .replace(/\bshift\b/gi, "")
.replace(/\balt\b/gi, "Alt") .replace(/\balt\b/gi, isMac ? "⌥" : "Alt")
.replace(/\bmod\b/gi, "Ctrl") .replace(/\bmod\b/gi, isMac ? "⌘" : "Ctrl")
.trim(); .trim();
} }