deleteItem.js 1.0 KB
Newer Older
Mr.奇淼('s avatar
Mr.奇淼( 已提交
1
/* eslint-disable */
Mr.奇淼('s avatar
Mr.奇淼( 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
export default function(G6) {
    G6.registerBehavior('deleteItem', {
        getEvents() {
            return {
                'keydown': 'onKeydown',
                'canvas:mouseleave': 'onCanvasLeave',
                'canvas:mouseenter': 'onCanvasFocus',
            }
        },
        onKeydown(e) {
            const items = this.graph.get('selectedItems');
            const focus = this.graph.get('focusGraphWrapper');
            if (e.keyCode === 46 && items && items.length > 0 && focus) {
                if (this.graph.executeCommand) {
                    this.graph.executeCommand('delete', {});
                } else {
                    this.graph.remove(items[0]);
                }
                this.graph.set('selectedItems', []);
                this.graph.emit('afteritemselected', []);
            }
        },
        onCanvasLeave(e) {
            this.graph.set('focusGraphWrapper', false);
        },
        onCanvasFocus() {
            this.graph.set('focusGraphWrapper', true);
29
        }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
30 31
    });
}