1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | require('slate');
|
8 |
|
9 | var _immutable = require('immutable');
|
10 |
|
11 |
|
12 |
|
13 | function firstDifferentCharacter(a, b) {
|
14 | if (a.length > b.length) {
|
15 | return firstDifferentCharacter(b, a);
|
16 | }
|
17 |
|
18 | var index = (0, _immutable.Range)(0, a.length).find(function (i) {
|
19 | return a[i] !== b[i];
|
20 | });
|
21 |
|
22 | return index == null ? a.length : index;
|
23 | }
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | function dedentLines(opts, change,
|
29 | // Indent to remove
|
30 | indent) {
|
31 | var value = change.value;
|
32 | var document = value.document,
|
33 | selection = value.selection;
|
34 |
|
35 | var lines = document.getBlocksAtRange(selection).filter(function (node) {
|
36 | return node.type === opts.lineType;
|
37 | });
|
38 |
|
39 | return lines.reduce(function (c, line) {
|
40 |
|
41 | var textNode = line.nodes.first();
|
42 | var lengthToRemove = firstDifferentCharacter(textNode.text, indent);
|
43 | return c.removeTextByKey(textNode.key, 0, lengthToRemove);
|
44 | }, change);
|
45 | }
|
46 |
|
47 | exports.default = dedentLines; |
\ | No newline at end of file |