Skip to content

Commit 574db47

Browse files
committed
Add desktop only setup of custom keymaps
Fix cloud and desktop app global search shortcut - Add desktop app changeable shortcut in menu - Fix cloud having multiple global search shortucts bound
1 parent 7f3a4bc commit 574db47

File tree

7 files changed

+63
-45
lines changed

7 files changed

+63
-45
lines changed

src/cloud/components/Application.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ const Application = ({
142142

143143
useEffect(() => {
144144
const handler = () => {
145-
if (usingElectron) {
146-
setShowFuzzyNavigation((prev) => !prev)
147-
}
145+
setShowFuzzyNavigation((prev) => !prev)
148146
}
149147
searchEventEmitter.listen(handler)
150148
return () => {

src/cloud/components/molecules/KeymapItemSection.tsx

+20-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import styled from '../../../design/lib/styled'
1414
import { inputStyle } from '../../../design/lib/styled/styleFunctions'
1515
import cc from 'classcat'
1616
import { useToast } from '../../../design/lib/stores/toast'
17+
import { useElectron } from '../../lib/stores/electron'
1718

1819
const invalidShortcutInputs = [' ']
1920
const rejectedShortcutInputs = [' ', 'control', 'alt', 'shift', 'meta']
@@ -28,6 +29,7 @@ interface KeymapItemSectionProps {
2829
) => Promise<void>
2930
removeKeymap: (key: string) => void
3031
description: string
32+
desktopOnly: boolean
3133
}
3234

3335
const KeymapItemSection = ({
@@ -36,6 +38,7 @@ const KeymapItemSection = ({
3638
updateKeymap,
3739
removeKeymap,
3840
description,
41+
desktopOnly,
3942
}: KeymapItemSectionProps) => {
4043
const [inputError, setInputError] = useState<boolean>(false)
4144
const [shortcutInputValue, setShortcutInputValue] = useState<string>('')
@@ -53,6 +56,7 @@ const KeymapItemSection = ({
5356
const shortcutInputRef = useRef<HTMLInputElement>(null)
5457

5558
const { pushMessage } = useToast()
59+
const { usingElectron } = useElectron()
5660

5761
const fetchInputShortcuts: KeyboardEventHandler<HTMLInputElement> = (
5862
event
@@ -137,6 +141,9 @@ const KeymapItemSection = ({
137141
? getGenericShortcutString(currentKeymapItem)
138142
: ''
139143
}, [currentKeymapItem, currentShortcut])
144+
145+
const isEditableKeymap = !desktopOnly || (desktopOnly && usingElectron)
146+
140147
return (
141148
<KeymapItemSectionContainer>
142149
<div>{description}</div>
@@ -155,18 +162,22 @@ const KeymapItemSection = ({
155162
onKeyDown={fetchInputShortcuts}
156163
/>
157164
)}
158-
<Button variant={'primary'} onClick={toggleChangingShortcut}>
159-
{currentShortcut == null
160-
? 'Assign'
161-
: changingShortcut
162-
? 'Apply'
163-
: 'Change'}
164-
</Button>
165-
{changingShortcut && (
165+
{!isEditableKeymap ? (
166+
<div>Desktop App Only</div>
167+
) : (
168+
<Button variant={'primary'} onClick={toggleChangingShortcut}>
169+
{currentShortcut == null
170+
? 'Assign'
171+
: changingShortcut
172+
? 'Apply'
173+
: 'Change'}
174+
</Button>
175+
)}
176+
{isEditableKeymap && changingShortcut && (
166177
<Button onClick={handleCancelKeymapChange}>Cancel</Button>
167178
)}
168179

169-
{currentShortcut != null && !changingShortcut && (
180+
{isEditableKeymap && currentShortcut != null && !changingShortcut && (
170181
<Button onClick={handleRemoveKeymap}>Un-assign</Button>
171182
)}
172183
</KeymapItemInputSection>

src/cloud/components/settings/KeymapTab.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ const KeymapTab = () => {
5757
description={keymapEntry[1].description}
5858
updateKeymap={updateKeymap}
5959
removeKeymap={removeKeymap}
60+
desktopOnly={
61+
keymapEntry[1].desktopOnly == null
62+
? false
63+
: keymapEntry[1].desktopOnly
64+
}
6065
/>
6166
)
6267
})}

src/cloud/lib/stores/electron.ts

-4
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,6 @@ const useElectronStore = (): ElectronStore => {
272272
event.preventDefault()
273273
toggleSettingsEventEmitter.dispatch()
274274
return
275-
case 'p':
276-
event.preventDefault()
277-
searchEventEmitter.dispatch()
278-
return
279275
case '0':
280276
if (event.shiftKey) {
281277
event.preventDefault()

src/electron/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ let ready = false
2020
const singleInstance = app.requestSingleInstanceLock()
2121

2222
export const keymap = new Map<string, string>([
23-
['toggleGlobalSearch', 'CmdOrCtrl + P'],
23+
['toggleGlobalSearch', 'CmdOrCtrl + p'],
2424
['toggleSplitEditMode', 'CmdOrCtrl + \\'],
25-
['togglePreviewMode', 'CmdOrCtrl + E'],
26-
['editorSaveAs', 'CmdOrCtrl + S'],
27-
['createNewDoc', 'CmdOrCtrl + N'],
28-
['createNewFolder', 'CmdOrCtrl + Shift + N'],
25+
['togglePreviewMode', 'CmdOrCtrl + e'],
26+
['editorSaveAs', 'CmdOrCtrl + s'],
27+
['createNewDoc', 'CmdOrCtrl + n'],
28+
// ['createNewFolder', 'CmdOrCtrl + Shift + N'],
2929
['resetZoom', 'CmdOrCtrl + 0'],
3030
['zoomOut', 'CmdOrCtrl + -'],
3131
['zoomIn', 'CmdOrCtrl + Plus'],

src/electron/menu.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function getTemplateFromKeymap(
2222
}
2323

2424
menu.push(getFileMenu(keymap))
25-
menu.push(getEditMenu())
25+
menu.push(getEditMenu(keymap))
2626
menu.push(getViewMenu(keymap))
2727
menu.push(getWindowMenu())
2828
menu.push(getCommunityMenu())
@@ -154,7 +154,7 @@ function getFileMenu(keymap: Map<string, string>): MenuItemConstructorOptions {
154154
}
155155
}
156156

157-
function getEditMenu(): MenuItemConstructorOptions {
157+
function getEditMenu(keymap: Map<string, string>): MenuItemConstructorOptions {
158158
const submenuItems: MenuItemConstructorOptions[] = [
159159
{ role: 'undo' },
160160
{ role: 'redo' },
@@ -167,7 +167,7 @@ function getEditMenu(): MenuItemConstructorOptions {
167167
type: 'normal',
168168
label: 'Search',
169169
click: createEmitIpcMenuItemHandler('search'),
170-
accelerator: mac ? 'Cmd + P' : 'Ctrl + P',
170+
accelerator: keymap.get('toggleGlobalSearch'),
171171
},
172172
{ type: 'separator' },
173173
{ role: 'delete' },

src/lib/keymap.ts

+29-21
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ export interface KeymapItem {
1818
shortcutSecondStroke?: KeymapItemEditableProps
1919
description: string
2020
isMenuType?: boolean
21+
desktopOnly?: boolean
2122
}
2223

2324
export const defaultKeymap = new Map<string, KeymapItem>([
2425
[
2526
'createNewDoc',
2627
{
2728
shortcutMainStroke: {
28-
key: 'N',
29+
key: 'n',
2930
keycode: 78,
3031
modifiers:
3132
osName === 'macos'
@@ -36,26 +37,29 @@ export const defaultKeymap = new Map<string, KeymapItem>([
3637
},
3738
description: 'Create new document',
3839
isMenuType: true,
40+
desktopOnly: true,
3941
},
4042
],
41-
[
42-
'createNewFolder',
43-
{
44-
shortcutMainStroke: {
45-
key: 'N',
46-
keycode: 78,
47-
modifiers:
48-
osName === 'macos'
49-
? { meta: true, shift: true }
50-
: {
51-
ctrl: true,
52-
shift: true,
53-
},
54-
},
55-
description: 'Create new folder',
56-
isMenuType: true,
57-
},
58-
],
43+
// todo: [komediruzecki-2021-12-5] Enable when available
44+
// [
45+
// 'createNewFolder',
46+
// {
47+
// shortcutMainStroke: {
48+
// key: 'N',
49+
// keycode: 78,
50+
// modifiers:
51+
// osName === 'macos'
52+
// ? { meta: true, shift: true }
53+
// : {
54+
// ctrl: true,
55+
// shift: true,
56+
// },
57+
// },
58+
// description: 'Create new folder',
59+
// isMenuType: true,
60+
// desktopOnly: true,
61+
// },
62+
// ],
5963
[
6064
'toggleSideNav',
6165
{
@@ -77,7 +81,7 @@ export const defaultKeymap = new Map<string, KeymapItem>([
7781
'toggleGlobalSearch',
7882
{
7983
shortcutMainStroke: {
80-
key: 'P',
84+
key: 'p',
8185
keycode: 80,
8286
modifiers:
8387
osName === 'macos'
@@ -105,6 +109,7 @@ export const defaultKeymap = new Map<string, KeymapItem>([
105109
},
106110
},
107111
description: 'Toggle in-page search modal dialog',
112+
desktopOnly: true,
108113
},
109114
],
110115
// todo: [komediruzecki-2021-11-7] enable once implemented
@@ -163,7 +168,7 @@ export const defaultKeymap = new Map<string, KeymapItem>([
163168
'togglePreviewMode',
164169
{
165170
shortcutMainStroke: {
166-
key: 'E',
171+
key: 'e',
167172
keycode: 69,
168173
modifiers:
169174
osName === 'macos'
@@ -208,6 +213,7 @@ export const defaultKeymap = new Map<string, KeymapItem>([
208213
},
209214
description: 'Zoom in window',
210215
isMenuType: true,
216+
desktopOnly: true,
211217
},
212218
],
213219
[
@@ -225,6 +231,7 @@ export const defaultKeymap = new Map<string, KeymapItem>([
225231
},
226232
description: 'Zoom out window',
227233
isMenuType: true,
234+
desktopOnly: true,
228235
},
229236
],
230237
[
@@ -242,6 +249,7 @@ export const defaultKeymap = new Map<string, KeymapItem>([
242249
},
243250
description: 'Reset window zoom',
244251
isMenuType: true,
252+
desktopOnly: true,
245253
},
246254
],
247255
// todo: [komediruzecki-2021-11-7] Enable once implemented

0 commit comments

Comments
 (0)