slate-edit-list
Version:
A Slate plugin to handle keyboard events in lists.
31 lines (24 loc) • 812 B
JavaScript
const expect = require('expect');
module.exports = function(plugin, state) {
const selectedBlock = state.document.getDescendant('_selection_key');
const withCursor = state.transform()
.collapseToStartOf(selectedBlock)
.moveForward(2) // It|em 1
.apply();
const transform = withCursor.transform();
const newState = plugin.transforms
.splitListItem(transform)
.apply();
// check new selection
const selectedNode = newState.document.getTexts().get(2);
expect(newState.selection.toJS()).toEqual({
anchorKey: selectedNode.key,
anchorOffset: 0,
focusKey: selectedNode.key,
focusOffset: 0,
isBackward: false,
isFocused: false,
marks: null
});
return newState;
};