Skip to content

Commit

Permalink
Add shortcut to zoom in/out
Browse files Browse the repository at this point in the history
Summary: Add zoom in/out shortcut with alt-plus/minus

Reviewed By: quark-zju

Differential Revision: D51869325

fbshipit-source-id: 95488fdeb31a39b7d3c1817c95f3293e69b88f16
  • Loading branch information
evangrayk authored and facebook-github-bot committed Dec 6, 2023
1 parent eca1863 commit be29694
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions addons/isl/src/ISLShortcuts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const [ISLCommandContext, useCommand, dispatchCommand, allCommands] = mak
ContinueSelectionDownwards: [Modifier.SHIFT, KeyCode.DownArrow],
SelectAllCommits: [Modifier.ALT, KeyCode.A],
HideSelectedCommits: [Modifier.NONE, KeyCode.Backspace],
ZoomIn: [Modifier.ALT, KeyCode.Plus],
ZoomOut: [Modifier.ALT, KeyCode.Minus],
ToggleTheme: [Modifier.ALT, KeyCode.T],
ToggleShelvedChangesDropdown: [Modifier.ALT, KeyCode.S],
ToggleDownloadCommitsDropdown: [Modifier.ALT, KeyCode.D],
Expand All @@ -54,6 +56,8 @@ export const ISLShortcutLabels: Partial<Record<ISLCommandName, string>> = {
OpenHeadChangesComparisonView: t('Open Head Changes Comparison View'),
SelectAllCommits: t('Select All Commits'),
ToggleTheme: t('Toggle Light/Dark Theme'),
ZoomIn: t('Zoom In'),
ZoomOut: t('Zoom Out'),
ToggleShelvedChangesDropdown: t('Toggle Shelved Changes Dropdown'),
ToggleDownloadCommitsDropdown: t('Toggle Download Commits Dropdown'),
ToggleCwdDropdown: t('Toggle CWD Dropdown'),
Expand Down
4 changes: 4 additions & 0 deletions addons/isl/src/Kbd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ function keycodeToString(keycode: KeyCode): string {
return '.';
case KeyCode.Escape:
return 'Esc';
case KeyCode.Plus:
return '+';
case KeyCode.Minus:
return '-';
default:
return String.fromCharCode(keycode).toUpperCase();
}
Expand Down
3 changes: 2 additions & 1 deletion addons/isl/src/SettingsTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {debugToolsEnabledState} from './debug/DebugToolsState';
import {t, T} from './i18n';
import {SetConfigOperation} from './operations/SetConfigOperation';
import platform from './platform';
import {renderCompactAtom, zoomUISettingAtom} from './responsive';
import {renderCompactAtom, useZoomShortcut, zoomUISettingAtom} from './responsive';
import {repositoryInfo, useRunOperation} from './serverAPIState';
import {useThemeShortcut, themeState} from './theme';
import {
Expand All @@ -43,6 +43,7 @@ import './SettingsTooltip.css';

export function SettingsGearButton() {
useThemeShortcut();
useZoomShortcut();
const showShortcutsHelp = useShowKeyboardShortcutsHelp();
return (
<Tooltip
Expand Down
11 changes: 11 additions & 0 deletions addons/isl/src/responsive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import {globalRecoil} from './AccessGlobalRecoil';
import {useCommand} from './ISLShortcuts';
import {
persistAtomToConfigEffect,
persistAtomToLocalStorageEffect,
Expand Down Expand Up @@ -40,6 +42,15 @@ export const zoomUISettingAtom = atom<number>({
],
});

export function useZoomShortcut() {
useCommand('ZoomIn', () => {
globalRecoil().set(zoomUISettingAtom, old => Math.round((old + 0.1) * 100) / 100);
});
useCommand('ZoomOut', () => {
globalRecoil().set(zoomUISettingAtom, old => Math.round((old - 0.1) * 100) / 100);
});
}

export function useMainContentWidth() {
const setMainContentWidth = useSetRecoilState(mainContentWidthState);

Expand Down
2 changes: 2 additions & 0 deletions addons/shared/KeyboardShortcuts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export enum KeyCode {
RightArrow = 39,
DownArrow = 40,
Backspace = 8,
Plus = 187,
Minus = 189,
}

type CommandDefinition = [Modifiers, KeyCode];
Expand Down

0 comments on commit be29694

Please sign in to comment.