UNPKG

820 BJavaScriptView Raw
1'use strict';
2
3var decreaseItemDepth = require('./changes/decreaseItemDepth');
4var increaseItemDepth = require('./changes/increaseItemDepth');
5var getCurrentItem = require('./getCurrentItem');
6
7/**
8 * User pressed Tab in an editor.
9 * Tab -> Increase item depth if inside a list item
10 * Shift+Tab -> Decrease item depth if inside a list item
11 */
12function onTab(event, change, editor, opts) {
13 var value = change.value;
14 var isCollapsed = value.isCollapsed;
15
16
17 if (!isCollapsed || !getCurrentItem(opts, value)) {
18 return;
19 }
20
21 // Shift+tab reduce depth
22 if (event.shiftKey) {
23 event.preventDefault();
24
25 return decreaseItemDepth(opts, change);
26 }
27
28 // Tab increases depth
29 event.preventDefault();
30
31 return increaseItemDepth(opts, change);
32}
33
34module.exports = onTab;
\No newline at end of file