-
Notifications
You must be signed in to change notification settings - Fork 79
/
note.ts
37 lines (33 loc) · 1.22 KB
/
note.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import Shortcut from '../@types/Shortcut'
import toggleNote from '../action-creators/toggleNote'
import PencilIcon from '../components/icons/PencilIcon'
import { HOME_PATH } from '../constants'
import asyncFocus from '../device/asyncFocus'
import attribute from '../selectors/attribute'
import simplifyPath from '../selectors/simplifyPath'
import head from '../util/head'
import isDocumentEditable from '../util/isDocumentEditable'
const noteShortcut: Shortcut = {
id: 'note',
label: 'Note',
description: 'Add a small note beneath a thought. Cute!',
keyboard: { key: 'n', alt: true, meta: true },
gesture: 'rdlr',
svg: PencilIcon,
canExecute: getState => isDocumentEditable() && !!getState().cursor,
exec: (dispatch, getState) => {
const state = getState()
const { cursor } = state
// check cursor in exec rather than short-circuiting in canExecute so that the default browser behavior is always prevented
if (!cursor) return
asyncFocus()
dispatch(toggleNote())
},
isActive: getState => {
const state = getState()
const { cursor } = state
const path = cursor ? simplifyPath(state, cursor) : HOME_PATH
return attribute(state, head(path), '=note') != null
},
}
export default noteShortcut