<commit_before>import Observer from './Observer.js';

/**
 * Widget Observer
 */
export default class WidgetObserver extends Observer {
    /**
     * @inheritDoc
     */
    observe(ev) {
        ev.forEach(item => item.addedNodes.forEach(node => {
            if (node instanceof HTMLElement && node.parentElement.isSameNode(this.editor.content)) {
                node.tabIndex = 0;
                node.addEventListener('keyup', ev => this.onKeyUp(ev));
                this.dragndrop(node);
            }
        }));
    }

    /**
     * Handles keyup events
     *
     * @private
     *
     * @param {KeyboardEvent} ev
     */
    onKeyUp(ev) {
        const node = ev.target;

        if (this.editor.document.activeElement.isSameNode(node)) {
            if (ev.key === 'Delete') {
                node.parentElement.removeChild(node);
                ev.preventDefault();
                ev.cancelBubble = true;
            } else if (node.draggable && ev.key === 'ArrowUp' && node.previousElementSibling) {
                node.previousElementSibling.insertAdjacentHTML('beforebegin', node.outerHTML);
                node.parentElement.removeChild(node);
                ev.preventDefault();
                ev.cancelBubble = true;
            } else if (node.draggable && ev.key === 'ArrowDown' && node.nextElementSibling) {
                node.nextElementSibling.insertAdjacentHTML('afterend', node.outerHTML);
                node.parentElement.removeChild(node);
                ev.preventDefault();
                ev.cancelBubble = true;
            }
        }
    }

    /**
     * Adds drag'n'drop support
     *
     * @private
     *
     * @param {HTMLElement} node
     */
    dragndrop(node) {
        const parentName = 'root';
        const keyName = 'text/x-editor-name';
        const keyHtml = 'text/x-editor-html';
        const toggle = () => {
            const hasDraggable = node.hasAttribute('draggable');

            this.editor.content.querySelectorAll('[draggable]').forEach(item => {
                item.removeAttribute('draggable');

                if (item.hasAttribute('contenteditable')) {
                    item.setAttribute('contenteditable', 'true');
                }
            });

            if (!hasDraggable) {
                node.setAttribute('draggable', 'true');

                if (node.hasAttribute('contenteditable')) {
                    node.setAttribute('contenteditable', 'false');<commit_msg>Fix regression with delete key<commit_after>import Observer from './Observer.js';

/**
 * Widget Observer
 */
export default class WidgetObserver extends Observer {
    /**
     * @inheritDoc
     */
    observe(ev) {
        ev.forEach(item => item.addedNodes.forEach(node => {
            if (node instanceof HTMLElement && node.parentElement.isSameNode(this.editor.content)) {
                node.tabIndex = 0;
                node.addEventListener('keyup', ev => {
                    if (this.editor.document.activeElement.isSameNode(node)) {
                        if (ev.key === 'Delete') {
                            node.parentElement.removeChild(node);
                            ev.preventDefault();
                            ev.cancelBubble = true;
                        } else if (node.draggable && ev.key === 'ArrowUp' && node.previousElementSibling) {
                            node.previousElementSibling.insertAdjacentHTML('beforebegin', node.outerHTML);
                            node.parentElement.removeChild(node);
                            ev.preventDefault();
                            ev.cancelBubble = true;
                        } else if (node.draggable && ev.key === 'ArrowDown' && node.nextElementSibling) {
                            node.nextElementSibling.insertAdjacentHTML('afterend', node.outerHTML);
                            node.parentElement.removeChild(node);
                            ev.preventDefault();
                            ev.cancelBubble = true;
                        }
                    }
                });
                this.dragndrop(node);
            }
        }));
    }

    /**
     * Adds drag'n'drop support
     *
     * @private
     *
     * @param {HTMLElement} node
     */
    dragndrop(node) {
        const parentName = 'root';
        const keyName = 'text/x-editor-name';
        const keyHtml = 'text/x-editor-html';
        const toggle = () => {
            const hasDraggable = node.hasAttribute('draggable');

            this.editor.content.querySelectorAll('[draggable]').forEach(item => {
                item.removeAttribute('draggable');

                if (item.hasAttribute('contenteditable')) {
                    item.setAttribute('contenteditable', 'true');
                }
            });

            if (!hasDraggable) {
                node.setAttribute('draggable', 'true');

                if (node.hasAttribute('contenteditable')) {
                    node.setAttribute('contenteditable', 'false');
{'fraction_non_alphanumeric': 0.1235752849430114, 'fraction_numerical': 0.0003999200159968006, 'mean_word_length': 1.587687532333161, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1998917', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1304, 'n_words': 205}