slate-edit-code
Version:
A Slate plugin to handle keyboard events in code blocks.
19 lines (15 loc) • 434 B
JavaScript
module.exports = function(plugin, state) {
let block = state.document.findDescendant(node => node.type == 'code_block');
let withCursor = state.transform()
.collapseToStartOf(block)
.moveToOffsets(0)
.apply();
return plugin.onKeyDown(
{
preventDefault: function() {},
stopPropagation: function() {}
},
{ key: 'tab' },
withCursor
);
};