UNPKG

812 BJavaScriptView Raw
1'use strict';
2
3var unwrapList = require('./changes/unwrapList');
4var getCurrentItem = require('./getCurrentItem');
5
6/**
7 * User pressed Delete in an editor
8 */
9function onBackspace(event, change, editor, opts) {
10 var value = change.value;
11 var startOffset = value.startOffset,
12 selection = value.selection;
13
14 // Only unwrap...
15 // ... with a collapsed selection
16
17 if (selection.isExpanded) return;
18
19 // ... when at the beginning of nodes
20 if (startOffset > 0) return;
21 // ... in a list
22 var currentItem = getCurrentItem(opts, value);
23 if (!currentItem) return;
24 // ... more precisely at the beginning of the current item
25 if (!selection.isAtStartOf(currentItem)) return;
26
27 event.preventDefault();
28 return unwrapList(opts, change);
29}
30
31module.exports = onBackspace;
\No newline at end of file