UNPKG

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