|
| 1 | +import * as _ from 'lodash'; |
| 2 | + |
| 3 | +import { SerializedBlock } from '../types'; |
| 4 | +import KeyMappings, { HotkeyMapping } from '../keyMappings'; |
| 5 | +import { motionKey } from '../keyDefinitions'; |
| 6 | +import { SINGLE_LINE_MOTIONS } from '../definitions/motions'; |
| 7 | +import Config from '../config'; |
| 8 | + |
| 9 | +export const INSERT_MOTION_MAPPINGS: HotkeyMapping = { |
| 10 | + 'motion-left': [['left']], |
| 11 | + 'motion-right': [['right']], |
| 12 | + 'motion-up': [['up']], |
| 13 | + 'motion-down': [['down']], |
| 14 | + 'motion-line-beginning': [['home'], ['ctrl+a'], ['meta+left']], |
| 15 | + 'motion-line-end': [['end'], ['ctrl+e'], ['meta+right']], |
| 16 | + 'motion-word-beginning': [['alt+b'], ['alt+left']], |
| 17 | + 'motion-word-end': [], |
| 18 | + 'motion-word-next': [['alt+f'], ['alt+right']], |
| 19 | + 'motion-Word-beginning': [], |
| 20 | + 'motion-Word-end': [], |
| 21 | + 'motion-Word-next': [], |
| 22 | + |
| 23 | + 'motion-visible-beginning': [['meta+home']], |
| 24 | + 'motion-visible-end': [['meta+end']], |
| 25 | + 'motion-parent': [['ctrl+g', 'p']], |
| 26 | + 'motion-next-clone': [['ctrl+g', 'c']], |
| 27 | + 'motion-next-sibling': [['alt+down']], |
| 28 | + 'motion-prev-sibling': [['alt+up']], |
| 29 | +}; |
| 30 | + |
| 31 | +export const INSERT_MODE_MAPPINGS: HotkeyMapping = Object.assign({ |
| 32 | + 'move-cursor-insert': [[motionKey]], |
| 33 | + 'toggle-help': [['ctrl+?'], ['meta+?']], |
| 34 | + 'fold-toggle': [], |
| 35 | + 'fold-open': [['meta+down']], |
| 36 | + 'fold-close': [['meta+up']], |
| 37 | + 'delete-blocks': [['meta+shift+delete']], |
| 38 | + 'delete-char-after': [['delete']], |
| 39 | + 'delete-char-before': [['backspace'], ['shift+backspace']], |
| 40 | + 'delete-to-line-beginning': [['ctrl+u']], |
| 41 | + 'delete-to-line-end': [['ctrl+k']], |
| 42 | + 'delete-to-word-beginning': [['ctrl+w']], |
| 43 | + // NOTE: paste-after doesn't make much sense for insert mode |
| 44 | + 'paste-before': [['ctrl+y']], |
| 45 | + 'split-line': [['enter']], |
| 46 | + 'scroll-down': [['page down']], |
| 47 | + 'scroll-up': [['page up']], |
| 48 | + 'undo': [['ctrl+z'], ['meta+z']], |
| 49 | + 'redo': [['ctrl+Z'], ['meta+Z'], ['meta+y']], |
| 50 | + 'unindent-row': [], |
| 51 | + 'indent-row': [], |
| 52 | + 'unindent-blocks': [['shift+tab']], |
| 53 | + 'indent-blocks': [['tab']], |
| 54 | + 'search': [['esc', 'ctrl+f']], |
| 55 | + 'swap-block-down': [['meta+shift+up']], |
| 56 | + 'swap-block-up': [['meta+shift+down']], |
| 57 | + 'toggle-cursor-bold': [['meta+b']], |
| 58 | + 'toggle-cursor-italic': [['meta+i']], |
| 59 | + 'toggle-cursor-underline': [['meta+u']], |
| 60 | + // NOTE: in workflowy, this also crosses out children |
| 61 | + 'toggle-cursor-strikethrough': [['meta+enter']], |
| 62 | + 'zoom-prev-sibling': [], |
| 63 | + 'zoom-next-sibling': [], |
| 64 | + 'zoom-in': [], |
| 65 | + 'zoom-out': [['meta+<']], |
| 66 | + 'zoom-cursor': [['meta+>']], |
| 67 | + 'zoom-root': [], |
| 68 | +}, INSERT_MOTION_MAPPINGS); |
| 69 | + |
| 70 | +export const SEARCH_MODE_MAPPINGS: HotkeyMapping = Object.assign({ |
| 71 | + 'move-cursor-search': [[motionKey]], |
| 72 | + 'toggle-help': [['ctrl+?']], |
| 73 | + 'exit-mode': [['esc'], ['ctrl+c']], |
| 74 | + 'search-delete-char-after': [['delete']], |
| 75 | + 'search-delete-char-before': [['backspace'], ['shift+backspace']], |
| 76 | + 'search-select': [['enter']], |
| 77 | + 'search-up': [['ctrl+k'], ['up'], ['shift+tab']], |
| 78 | + 'search-down': [['ctrl+j'], ['down'], ['tab']], |
| 79 | +}, _.pick(INSERT_MOTION_MAPPINGS, SINGLE_LINE_MOTIONS)); |
| 80 | + |
| 81 | +export const SETTINGS_MODE_MAPPINGS: HotkeyMapping = { |
| 82 | + 'exit-mode': [['esc'], ['ctrl+c']], |
| 83 | +}; |
| 84 | + |
| 85 | +// TODO fix this |
| 86 | +const defaultData: Array<SerializedBlock> = [ |
| 87 | + 'Welcome to vimflowy!', |
| 88 | + { text: 'Features', children: [ |
| 89 | + { text: 'Workflowy features', children: [ |
| 90 | + { text: 'Nested bullets', children: [ |
| 91 | + 'Bullets with children can be collapsed', |
| 92 | + { text: 'Use enter to zoom into any bullet. Try on this one', collapsed: true, children: [ |
| 93 | + 'And shift+enter to zoom all the way back out', |
| 94 | + 'Use ] and [ to zoom in and out just one level', |
| 95 | + ] }, |
| 96 | + { text: 'Use z to toggle collapsedness', collapsed: true, children: [ |
| 97 | + 'You found me :)', |
| 98 | + ] }, |
| 99 | + 'Use tab and shift+tab to indent and unindent blocks', |
| 100 | + 'Use < and > to indent and unindent just a single line', |
| 101 | + ] }, |
| 102 | + { text: 'Text formatting', collapsed: true, children: [ |
| 103 | + { |
| 104 | + text: 'Bold, italicized, and underlined text. Emphatic!', |
| 105 | + properties: { |
| 106 | + bold: '.... ........ ', |
| 107 | + italic: ' .......... ........ ', |
| 108 | + underline: ' .......... ........ ', |
| 109 | + }, |
| 110 | + }, |
| 111 | + { |
| 112 | + text: 'Strike through', |
| 113 | + children: [ { |
| 114 | + text: 'Useful for todo lists', |
| 115 | + properties: { |
| 116 | + strikethrough: '.....................', |
| 117 | + }, |
| 118 | + } ], |
| 119 | + }, |
| 120 | + ] }, |
| 121 | + ] }, |
| 122 | + 'Press / to start searching for text', |
| 123 | + { text: 'Marks', plugins: { mark: 'mark' }, collapsed: true, children: [ |
| 124 | + { text: 'I am marked!', plugins: { mark: 'im_a_mark' } }, |
| 125 | + 'Press m to start marking a line, and enter to finish', |
| 126 | + 'Use \' to search and jump to marks', |
| 127 | + 'Link to marks with the @ symbol, like this: @im_a_mark. Use gm to follow the link.', |
| 128 | + 'Delete marks by using dm, or just mark with empty string', |
| 129 | + ] }, |
| 130 | + { text: 'Cloning', collapsed: true, children: [ |
| 131 | + { text: 'I am a clone! Try editing me', id: 1 }, |
| 132 | + { text: 'Clones can\'t be siblings or descendants of each other', children: [ |
| 133 | + { clone: 1 }, |
| 134 | + ] }, |
| 135 | + 'Make new clones with yc, then p', |
| 136 | + ] }, |
| 137 | + { text: 'Customizability', collapsed: true, children: [ |
| 138 | + { text: 'Plugins system', collapsed: true, children: [ |
| 139 | + 'See the settings menu to turn on some plugins!', |
| 140 | + 'If you\'re interested in writing plugins, see here: ' + |
| 141 | + 'https://github.com/WuTheFWasThat/vimflowy/blob/master/docs/plugins.md', |
| 142 | + ] }, |
| 143 | + 'Customizable hotkeys (via downloading/uploading a json file)', |
| 144 | + 'Different color themes (see Settings)', |
| 145 | + ] }, |
| 146 | + ] }, |
| 147 | + { text: 'Data', collapsed: true, children: [ |
| 148 | + { text: 'Backing storage', children: [ |
| 149 | + 'Vimflowy was designed to be agnostic to the storage backend', |
| 150 | + 'As a user, you are in full control of your data', |
| 151 | + 'By default, all data is entirely local', |
| 152 | + 'There are no backups, and it is never sent over the internet', |
| 153 | + 'However, remote data storage is supported', |
| 154 | + 'To manage your data, visit the Settings menu', |
| 155 | + ] }, |
| 156 | + { text: 'Importing and exporting data', children: [ |
| 157 | + 'Two import and export formats are supported.', |
| 158 | + 'Check out settings for more information.', |
| 159 | + 'You can regularly export your data in JSON format, as a form of backup', |
| 160 | + ] }, |
| 161 | + ] }, |
| 162 | + { text: 'Tips', collapsed: true, children: [ |
| 163 | + 'Collapse things often to avoid clutter. Zoom into collapsed bullets', |
| 164 | + 'Want to go back to where you were? ctrl+o jumps back in your location history (ctrl+i jumps forward)', |
| 165 | + 'Check out the cheat sheet on the right. Once you become an expert, you can hide it', |
| 166 | + ] }, |
| 167 | + 'Press i to enter insert mode and start adding your own content!', |
| 168 | + 'For more info, visit https://github.com/WuTheFWasThat/vimflowy (visit links under the cursor with gx)', |
| 169 | +]; |
| 170 | + |
| 171 | +const config: Config = { |
| 172 | + type: 'workflowy', |
| 173 | + defaultMode: 'INSERT', |
| 174 | + defaultData: defaultData, |
| 175 | + // TODO: get the keys from modes.ts |
| 176 | + defaultMappings: |
| 177 | + new KeyMappings({ |
| 178 | + [ 'INSERT' ]: INSERT_MODE_MAPPINGS, |
| 179 | + [ 'SEARCH' ]: SEARCH_MODE_MAPPINGS, |
| 180 | + [ 'SETTINGS' ]: SETTINGS_MODE_MAPPINGS, |
| 181 | + }), |
| 182 | +}; |
| 183 | +export default config; |
0 commit comments