UNPKG

851 BJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7require('slate');
8
9/**
10 * Dedent all lines in selection
11 */
12function dedentLines(opts, change,
13// Indent to remove
14indent) {
15 var value = change.value;
16 var document = value.document,
17 selection = value.selection;
18
19 var lines = document.getBlocksAtRange(selection).filter(function (node) {
20 return node.type === opts.lineType;
21 });
22
23 return lines.reduce(function (c, line) {
24 // Remove a level of indent from the start of line
25 var text = line.nodes.first();
26 var lengthToRemove = text.characters.takeWhile(function (char, index) {
27 return indent.charAt(index) === char.text;
28 }).count();
29 return c.removeTextByKey(text.key, 0, lengthToRemove);
30 }, change);
31}
32exports.default = dedentLines;
\No newline at end of file