Skip to content

Commit

Permalink
* Make Cmd left/right go back/forward
Browse files Browse the repository at this point in the history
  • Loading branch information
PikachuEXE committed Dec 28, 2024
1 parent 53568e3 commit aeffacb
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ const KeyboardShortcuts = {
SHOW_SHORTCUTS: 'shift+?',
HISTORY_BACKWARD: 'alt+arrowleft',
HISTORY_FORWARD: 'alt+arrowright',
HISTORY_BACKWARD_ALT_MAC: 'cmd+arrowleft',
HISTORY_FORWARD_ALT_MAC: 'cmd+arrowright',
FULLSCREEN: 'f11',
NAVIGATE_TO_SETTINGS: 'ctrl+,',
NAVIGATE_TO_HISTORY: 'ctrl+H',
Expand Down
28 changes: 28 additions & 0 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,20 @@ function runApp() {
},
type: 'normal',
},
...(process.platform === 'darwin'
? [
{
label: 'Back',
accelerator: 'Cmd+Left',
click: (_menuItem, browserWindow, _event) => {
if (browserWindow == null) { return }

browserWindow.webContents.navigationHistory.goBack()
},
visible: false,
},
]
: []),
{
label: 'Forward',
accelerator: 'Alt+Right',
Expand All @@ -1712,6 +1726,20 @@ function runApp() {
},
type: 'normal',
},
...(process.platform === 'darwin'
? [
{
label: 'Forward',
accelerator: 'Cmd+Right',
click: (_menuItem, browserWindow, _event) => {
if (browserWindow == null) { return }

browserWindow.webContents.navigationHistory.goForward()
},
visible: false,
},
]
: []),
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ const localizedShortcutNameDictionary = computed(() => {
['SHOW_SHORTCUTS', t('KeyboardShortcutPrompt.Show Keyboard Shortcuts')],
['HISTORY_BACKWARD', t('KeyboardShortcutPrompt.History Backward')],
['HISTORY_FORWARD', t('KeyboardShortcutPrompt.History Forward')],
...(
isMac
? [
['HISTORY_BACKWARD_ALT_MAC', t('KeyboardShortcutPrompt.History Backward (Mac only)')],
['HISTORY_FORWARD_ALT_MAC', t('KeyboardShortcutPrompt.History Forward (Mac only)')],
]
: []
),
['FULLSCREEN', t('KeyboardShortcutPrompt.Fullscreen')],
['NAVIGATE_TO_SETTINGS', t('KeyboardShortcutPrompt.Navigate to Settings')],
(
Expand Down
14 changes: 12 additions & 2 deletions src/renderer/components/top-nav/top-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,26 @@ export default defineComponent({
},

forwardText: function () {
const shortcuts = [KeyboardShortcuts.APP.GENERAL.HISTORY_FORWARD]
if (process.platform === 'darwin') {
shortcuts.push(KeyboardShortcuts.APP.GENERAL.HISTORY_FORWARD_ALT_MAC)
}

return localizeAndAddKeyboardShortcutToActionTitle(
this.$t('Forward'),
KeyboardShortcuts.APP.GENERAL.HISTORY_FORWARD
shortcuts,
) + this.navigationHistoryAddendum
},

backwardText: function () {
const shortcuts = [KeyboardShortcuts.APP.GENERAL.HISTORY_BACKWARD]
if (process.platform === 'darwin') {
shortcuts.push(KeyboardShortcuts.APP.GENERAL.HISTORY_BACKWARD_ALT_MAC)
}

return localizeAndAddKeyboardShortcutToActionTitle(
this.$t('Back'),
KeyboardShortcuts.APP.GENERAL.HISTORY_BACKWARD
shortcuts,
) + this.navigationHistoryAddendum
},

Expand Down
12 changes: 8 additions & 4 deletions src/renderer/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1021,10 +1021,14 @@ export function addKeyboardShortcutToActionTitle(actionTitle, shortcut) {

/**
* @param {string} localizedActionTitle
* @param {string} unlocalizedShortcut
* @param {string|string[]} sometimesManyUnlocalizedShortcuts
* @returns {string} the localized action title with keyboard shortcut
*/
export function localizeAndAddKeyboardShortcutToActionTitle(localizedActionTitle, unlocalizedShortcut) {
const localizedShortcut = getLocalizedShortcut(unlocalizedShortcut)
return addKeyboardShortcutToActionTitle(localizedActionTitle, localizedShortcut)
export function localizeAndAddKeyboardShortcutToActionTitle(localizedActionTitle, sometimesManyUnlocalizedShortcuts) {
let unlocalizedShortcuts = sometimesManyUnlocalizedShortcuts
if (!Array.isArray(sometimesManyUnlocalizedShortcuts)) {
unlocalizedShortcuts = [unlocalizedShortcuts]
}
const localizedShortcuts = unlocalizedShortcuts.map((s) => getLocalizedShortcut(s))
return addKeyboardShortcutToActionTitle(localizedActionTitle, localizedShortcuts.join('/'))
}
2 changes: 2 additions & 0 deletions static/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,8 @@ KeyboardShortcutPrompt:
Show Keyboard Shortcuts: Show keyboard shortcuts
History Backward: Go back one page
History Forward: Go forward one page
History Backward (Mac only): Go back one page (Mac only)
History Forward (Mac only): Go forward one page (Mac only)
New Window: Create a new window
Navigate to Settings: Navigate to the Settings page
Navigate to History: Navigate to the History page
Expand Down

0 comments on commit aeffacb

Please sign in to comment.