UNPKG

slate-edit-code

Version:

A Slate plugin to handle keyboard events in code blocks.

19 lines (15 loc) 436 B
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: 'enter' }, withCursor ); };