UNPKG

702 BJavaScriptView Raw
1'use strict';
2
3var getCurrentIndent = require('./getCurrentIndent');
4var indentLines = require('./changes/indentLines');
5
6/**
7 * User pressed Tab in an editor:
8 * Insert a tab after detecting it from code block content.
9 */
10function onTab(event, data, change, opts) {
11 var state = change.state;
12
13 event.preventDefault();
14 event.stopPropagation();
15
16 var isCollapsed = state.isCollapsed;
17
18 var indent = getCurrentIndent(opts, state);
19
20 // Selection is collapsed, we just insert an indent at cursor
21 if (isCollapsed) {
22 return change.insertText(indent).focus();
23 }
24
25 // We indent all selected lines
26 return indentLines(opts, change, indent);
27}
28
29module.exports = onTab;
\No newline at end of file