Skip to content

Vary shortcut by OS, automatically #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 30, 2024
Merged
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 source/_locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"message": "Nach Name suchen…"
},
"undoInfoMsg": {
"message": "Du kannst deine letzte Aktionen rückgäng machen oder wiederherstellen. Dies funktioniert aber nur solange wie dieser Popup-Dialog geöffnet ist. Drücke dazu <kbd>Strg+z</kbd> unter Windows und <kbd>cmd+z</kbd> unter macOS, <kbd>super+z</kbd> unter Ubuntu."
"message": "Du kannst deine letzte Aktionen rückgäng machen oder wiederherstellen. Dies funktioniert aber nur solange wie dieser Popup-Dialog geöffnet ist. Drücke dazu <kbd>Strg+Z</kbd>."
},
"uninstall": {
"message": "Erweiterung entfernen…"
Expand Down
2 changes: 1 addition & 1 deletion source/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"message": "Search by name…"
},
"undoInfoMsg": {
"message": "You can undo and redo your last action until you close this popup. Press <kbd>ctrl+z</kbd> on Windows or Ubuntu, and <kbd>cmd+z</kbd> on macOS."
"message": "You can undo (with <kbd>Ctrl+Z</kbd>) and redo your last action until you close this popup."
},
"uninstall": {
"message": "Remove from Chrome"
Expand Down
2 changes: 1 addition & 1 deletion source/_locales/es/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"message": "Buscar por nombre…"
},
"undoInfoMsg": {
"message": "Puedes deshacer y rehacer tu última acción hasta que cierres esta ventana. Presiona <kbd>ctrl+z</kbd> en Windows y <kbd>cmd+z</kbd> en macOS, <kbd>super+z</kbd> en Ubuntu."
"message": "Puedes deshacer (con <kbd>Ctrl+Z</kbd>) y rehacer tu última acción hasta que cierres esta ventana."
},
"uninstall": {
"message": "Eliminar"
Expand Down
2 changes: 1 addition & 1 deletion source/_locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"hash": "1220702106584c8c90c0f41c486a3e0b"
},
"undoInfoMsg": {
"message": "Vous pouvez annuler et refaire votre dernière action jusqu'à ce que vous fermiez cette fenêtre contextuelle. Appuyez sur <kbd>ctrl+z</kbd> sur Windows et <kbd>cmd+z</kbd> sur macOS, <kbd>super+z</kbd> sur Ubuntu.",
"message": "Vous pouvez annuler et refaire votre dernière action jusqu'à ce que vous fermiez cette fenêtre contextuelle. Appuyez sur <kbd>Ctrl+Z</kbd>.",
"hash": "4105b6ebe6d3c7badf1a2bf9d425ddbb"
},
"uninstall": {
Expand Down
2 changes: 1 addition & 1 deletion source/_locales/he/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"message": "חיפוש תוסף לפי שם"
},
"undoInfoMsg": {
"message": "ניתן לבטל או לבצע מחדש פעולות עד לסגירת החלון באמצעות <kbd>ctrl+z</kbd> ב - windows, <kbd>cmd+z</kbd> ב - macOS או <kbd>super+z</kbd> ב Ubuntu."
"message": "ניתן לבטל או לבצע מחדש פעולות עד לסגירת החלון באמצעות <kbd>Ctrl+Z</kbd>."
},
"uninstall": {
"message": "להסיר את התוסף"
Expand Down
2 changes: 1 addition & 1 deletion source/_locales/it/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"hash": "1220702106584c8c90c0f41c486a3e0b"
},
"undoInfoMsg": {
"message": "Puoi annullare e ripetere la tua ultima azione finché non chiudi questo popup. Premi <kbd>ctrl+z</kbd> su Windows, <kbd>cmd+z</kbd> su macOS o <kbd>super+z</kbd> on Ubuntu.",
"message": "Puoi annullare (con <kbd>Ctrl+Z</kbd>) e ripetere la tua ultima azione finché non chiudi questo popup.",
"hash": "4c9adc1bb6418b3ecbc77f3ddda22a70"
},
"uninstall": {
Expand Down
2 changes: 1 addition & 1 deletion source/_locales/nl/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"hash": "1220702106584c8c90c0f41c486a3e0b"
},
"undoInfoMsg": {
"message": "Je kan je laatste actie ongedaan maken of opnieuw uitvoeren totdat je deze popup sluit. Druk op <kbd>ctrl+z</kbd> op Windows of Ubuntu, en <kbd>cmd+z</kbd> op MacOS.",
"message": "Je kan je laatste actie ongedaan maken of opnieuw uitvoeren totdat je deze popup sluit. Druk op <kbd>Ctrl+Z</kbd>.",
"hash": "b8be6c1fc88c7e6042b054effb2c6981"
},
"uninstall": {
Expand Down
2 changes: 1 addition & 1 deletion source/_locales/tr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"hash": "1220702106584c8c90c0f41c486a3e0b"
},
"undoInfoMsg": {
"message": "Bu pencere kapanıncaya kadar son işleminizi geri ya da ileri alabilirsiniz. Windows’ta <kbd>ctrl+z</kbd>’ye, macOS’te <kbd>cmd+z</kbd>’ye.",
"message": "Bu pencere kapanıncaya kadar son işleminizi geri ya da ileri alabilirsiniz. <kbd>Ctrl+Z</kbd>’ye.",
"hash": "4105b6ebe6d3c7badf1a2bf9d425ddbb"
},
"uninstall": {
Expand Down
2 changes: 1 addition & 1 deletion source/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"message": "查找扩展"
},
"undoInfoMsg": {
"message": "在关闭这个窗口前你可以撤销你的操作。 在 Windows 或 Ubuntu 中按 <kbd>Ctrl+Z</kbd>, macOS 中按<kbd>CMD+Z</kbd>."
"message": "在关闭这个窗口前你可以撤销你的操作。 中按 <kbd>Ctrl+Z</kbd>"
},
"uninstall": {
"message": "卸载这个扩展"
Expand Down
2 changes: 1 addition & 1 deletion source/_locales/zh_TW/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"hash": "1220702106584c8c90c0f41c486a3e0b"
},
"undoInfoMsg": {
"message": "在關閉這個窗口前你可以撤銷你的操作。 <br>在 Windows 或 Ubuntu 中按<kbd>ctrl+z</kbd>, macOS 中按<kbd>cmd+z</kbd>。",
"message": "在關閉這個窗口前你可以撤銷你的操作。 中按<kbd>Ctrl+Z</kbd>。",
"hash": "4105b6ebe6d3c7badf1a2bf9d425ddbb"
},
"uninstall": {
Expand Down
2 changes: 1 addition & 1 deletion source/app.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
<main>
{#if showInfoMessage && !userClickedHideInfoMessage}
<p class="notice">
{@html getI18N('undoInfoMsg')}
{@html UndoStack.replaceKbdOnMac(getI18N('undoInfoMsg'))}
<a class="hide-action" href="#hide" on:click={hideInfoMessage}
>{getI18N('hideInfoMsg')}</a
>
Expand Down
12 changes: 8 additions & 4 deletions source/lib/undo-stack.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
export default class UndoStack {
_undoStack = [];
_redoStack = [];
_Z_KEY = 90;
_isWin = navigator.userAgent.match(/win/i);
static isMac = navigator.platform.includes('Mac');
static replaceKbdOnMac = string =>
UndoStack.isMac
? // Some locales don't call it "ctrl"
string.replace(/(?<=>)[a-z]+\+z/i, '⌘Z')
: string;

constructor(element) {
if (element) {
Expand All @@ -12,8 +16,8 @@ export default class UndoStack {

#keyboardEventListener = event => {
if (
event.keyCode === this._Z_KEY &&
(this._isWin ? event.ctrlKey : event.metaKey)
event.code === 'KeyZ' &&
(UndoStack._isMac ? event.metaKey : event.ctrlKey)
) {
if (event.shiftKey) {
this.redo();
Expand Down
4 changes: 4 additions & 0 deletions source/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ a {
text-decoration: none;
}

kbd {
font-family: system-ui, monospace;
}

button {
display: inline-block;
padding: 0;
Expand Down
Loading