Skip to content

Commit d2a8b45

Browse files
committed
workflowy wip
1 parent 124f285 commit d2a8b45

File tree

6 files changed

+207
-6
lines changed

6 files changed

+207
-6
lines changed

src/assets/js/app.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { PluginsManager } from './plugins';
3636
import Path from './path';
3737
import Session from './session';
3838
import { SerializedBlock } from './types';
39-
import Config from './config';
39+
import Config, { ConfigType } from './config';
4040
import vimConfig from './configurations/vim';
4141

4242
import keyDefinitions from './keyDefinitions';
@@ -110,6 +110,7 @@ async function create_session(
110110
config: Config,
111111
dataSource: DataStore.DataSource, settings: Settings, doc: Document, to_load: Array<SerializedBlock>
112112
) {
113+
113114
let caughtErr: null | Error = null;
114115

115116
window.onerror = function(msg: string, url: string, line: number, _col: number, err: Error) {
@@ -401,7 +402,14 @@ $(document).ready(async () => {
401402
dataSource = await settings.getDocSetting('dataSource');
402403
}
403404

404-
const config: Config = vimConfig;
405+
const conf_type: ConfigType = 'vim';
406+
let config: Config;
407+
if (conf_type === 'vim') {
408+
config = vimConfig;
409+
} else {
410+
// TODO: workflowy config
411+
config = vimConfig;
412+
}
405413

406414
if (dataSource === 'firebase') {
407415
const [

src/assets/js/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import KeyMappings from './keyMappings';
55
// TODO: starting mode
66
// TODO: starting text (i.e. constants.default_data)
77

8+
export type ConfigType = 'vim' | 'workflowy';
9+
810
type Config = {
11+
type: ConfigType;
912
defaultMode: ModeId;
1013
defaultData: Array<SerializedBlock>;
1114
// NOTE: can be mutated when there's a mode registered

src/assets/js/configurations/vim.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ const defaultData: Array<SerializedBlock> = [
341341
];
342342

343343
const config: Config = {
344+
type: 'vim',
344345
defaultMode: 'NORMAL',
345346
defaultData: defaultData,
346347
// TODO: get the keys from modes.ts
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
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;

src/assets/js/definitions/motions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,4 @@ export const SINGLE_LINE_MOTIONS = [
207207
'motion-to-next-char',
208208
'motion-to-prev-char',
209209
];
210+

test/testcase.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Register, { RegisterTypes, SerializedRegister } from '../src/assets/js/re
1010
import '../src/assets/js/definitions';
1111
import mainDefinitions from '../src/assets/js/keyDefinitions';
1212
import KeyBindings from '../src/assets/js/keyBindings';
13-
import Config from '../src/assets/js/config';
13+
import Config, { ConfigType } from '../src/assets/js/config';
1414
import vimConfig from '../src/assets/js/configurations/vim';
1515
import KeyHandler from '../src/assets/js/keyHandler';
1616
import logger, * as Logger from '../src/assets/js/logger';
@@ -26,10 +26,13 @@ afterEach('empty the queue', () => logger.empty());
2626
// share keybindings across tests, for efficiency
2727
// note that the bindings will change when plugins are enabled and disabled
2828
// thus, tests are not totally isolated
29-
const keyBindings: KeyBindings = new KeyBindings(mainDefinitions, vimConfig.defaultMappings);
29+
const sharedKeyBindings: {[key: string]: KeyBindings} = {
30+
'vim': new KeyBindings(mainDefinitions, vimConfig.defaultMappings),
31+
};
3032

3133
type TestCaseOptions = {
3234
plugins?: Array<string>,
35+
config?: ConfigType,
3336
};
3437

3538
class TestCase {
@@ -48,16 +51,18 @@ class TestCase {
4851

4952
this.plugins = options.plugins || [];
5053

54+
const bindings: KeyBindings = sharedKeyBindings[options.config || 'vim'];
55+
5156
this.session = new Session(this.document, {
5257
viewRoot: Path.root(),
5358
});
5459

5560
const config: Config = vimConfig;
5661

57-
this.keyhandler = new KeyHandler(this.session, keyBindings);
62+
this.keyhandler = new KeyHandler(this.session, bindings);
5863
this.register = this.session.register;
5964

60-
this.pluginManager = new PluginsManager(this.session, config, keyBindings);
65+
this.pluginManager = new PluginsManager(this.session, config, bindings);
6166

6267
this.prom = Promise.resolve();
6368
this.plugins.forEach((pluginName) => {

0 commit comments

Comments
 (0)