Skip to content

Commit e18548f

Browse files
authored
Merge pull request #2395 from sdivyanshu90/keyboard_shortcut_add_file
Added a keyboard shortcut for adding files
2 parents 736cc60 + 03ca536 commit e18548f

File tree

6 files changed

+26
-2
lines changed

6 files changed

+26
-2
lines changed

client/common/useKeyDownHandlers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export default function useKeyDownHandlers(keyHandlers) {
3838
/^\d+$/.test(e.code.at(-1)) ? e.code.at(-1) : e.key.toLowerCase()
3939
}`
4040
]?.(e);
41+
} else if (isCtrl && e.altKey && e.code === 'KeyN') {
42+
// specifically for creating a new file
43+
handlers.current[`ctrl-alt-n`]?.(e);
4144
} else if (isCtrl) {
4245
handlers.current[`ctrl-${e.key.toLowerCase()}`]?.(e);
4346
}

client/modules/IDE/components/Header/Nav.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ const ProjectMenu = () => {
133133

134134
const replaceCommand =
135135
metaKey === 'Ctrl' ? `${metaKeyName}+H` : `${metaKeyName}+⌥+F`;
136+
const newFileCommand =
137+
metaKey === 'Ctrl' ? `${metaKeyName}+Alt+N` : `${metaKeyName}+⌥+N`;
136138

137139
return (
138140
<ul className="nav__items-left" role="menubar">
@@ -220,6 +222,7 @@ const ProjectMenu = () => {
220222
<NavDropdownMenu id="sketch" title={t('Nav.Sketch.Title')}>
221223
<NavMenuItem onClick={() => dispatch(newFile(rootFile.id))}>
222224
{t('Nav.Sketch.AddFile')}
225+
<span className="nav__keyboard-shortcut">{newFileCommand}</span>
223226
</NavMenuItem>
224227
<NavMenuItem onClick={() => dispatch(newFolder(rootFile.id))}>
225228
{t('Nav.Sketch.AddFolder')}

client/modules/IDE/components/Header/__snapshots__/Nav.unit.test.jsx.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,11 @@ exports[`Nav renders editor version for desktop 1`] = `
637637
role="menuitem"
638638
>
639639
Add File
640+
<span
641+
class="nav__keyboard-shortcut"
642+
>
643+
Ctrl+Alt+N
644+
</span>
640645
</button>
641646
</li>
642647
<li

client/modules/IDE/components/IDEKeyHandlers.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
expandSidebar,
99
showErrorModal,
1010
startSketch,
11-
stopSketch
11+
stopSketch,
12+
newFile
1213
} from '../actions/ide';
1314
import { setAllAccessibleOutput } from '../actions/preferences';
1415
import { cloneProject, saveProject } from '../actions/project';
@@ -72,6 +73,11 @@ export const useIDEKeyHandlers = ({ getContent }) => {
7273
sidebarIsExpanded ? collapseSidebar() : expandSidebar()
7374
);
7475
},
76+
'ctrl-alt-n': (e) => {
77+
e.preventDefault();
78+
e.stopPropagation();
79+
dispatch(newFile());
80+
},
7581
'ctrl-`': (e) => {
7682
e.preventDefault();
7783
dispatch(consoleIsExpanded ? collapseConsole() : expandConsole());

client/modules/IDE/components/KeyboardShortcutModal.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ function KeyboardShortcutModal() {
66
const { t } = useTranslation();
77
const replaceCommand =
88
metaKey === 'Ctrl' ? `${metaKeyName} + H` : `${metaKeyName} + ⌥ + F`;
9+
const newFileCommand =
10+
metaKey === 'Ctrl' ? `${metaKeyName} + Alt + N` : `${metaKeyName} + ⌥ + N`;
911
return (
1012
<div className="keyboard-shortcuts">
1113
<h3 className="keyboard-shortcuts__title">
@@ -69,6 +71,10 @@ function KeyboardShortcutModal() {
6971
<span className="keyboard-shortcut__command">{metaKeyName} + K</span>
7072
<span>{t('KeyboardShortcuts.CodeEditing.ColorPicker')}</span>
7173
</li>
74+
<li className="keyboard-shortcut-item">
75+
<span className="keyboard-shortcut__command">{newFileCommand}</span>
76+
<span>{t('KeyboardShortcuts.CodeEditing.CreateNewFile')}</span>
77+
</li>
7278
</ul>
7379
<h3 className="keyboard-shortcuts__title">General</h3>
7480
<ul className="keyboard-shortcuts__list">

translations/locales/en-US/translations.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@
207207
"FindNextTextMatch": "Find Next Text Match",
208208
"FindPreviousTextMatch": "Find Previous Text Match",
209209
"CodeEditing": "Code Editing",
210-
"ColorPicker": "Show Inline Color Picker"
210+
"ColorPicker": "Show Inline Color Picker",
211+
"CreateNewFile": "Create New File"
211212
},
212213
"General": {
213214
"StartSketch": "Start Sketch",

0 commit comments

Comments
 (0)