Get a block after pressing a key

This example shows how to get a block after pressing the enter key and manipulate it. Press enter in any text block to see the result.

Code

<!-- element -->
<textarea id="entry">...</textarea>

<!-- call -->
<script>
let app = Redactor('#entry', {
    subscribe: {
        'editor.keyup': function(event) {
            let e = event.get('e');
            let key = e.which;
            if (key === 13 && !e.shiftKey && !e.ctrlKey && !e.metaKey) {
                let instance = this.app.block.get();
                let $block = instance.getBlock();

                // example of manipulation of a block
                $block.html('My text');

                // set caret to the end
                let caret = this.app.create('caret');
                caret.set($block, 'end')
            }
        }
    }
});
</script>