From b4752b4855bafcdcc30f5a4c660f24450e7653fe Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Wed, 18 Oct 2017 02:22:02 +0200 Subject: [PATCH] Bind onSelect to component change in selectComponent command --- src/commands/view/SelectComponent.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/commands/view/SelectComponent.js b/src/commands/view/SelectComponent.js index 4e07067fe..7d49dd426 100644 --- a/src/commands/view/SelectComponent.js +++ b/src/commands/view/SelectComponent.js @@ -90,6 +90,7 @@ module.exports = { * @private * */ toggleSelectComponent(enable) { + const em = this.em; const method = enable ? 'on' : 'off'; const methods = {on, off}; const body = this.getCanvasBody(); @@ -99,6 +100,7 @@ module.exports = { methods[method](body, 'click', this.onClick); methods[method](win, 'scroll', this.onFrameScroll); methods[method](win, 'keydown', this.onKeyPress); + em[method]('change:selectedComponent', this.onSelect, this); }, /** @@ -221,18 +223,14 @@ module.exports = { }, /** - * Hover command - * @param {Object} e + * On element click + * @param {Event} e * @private */ onClick(e) { - var m = $(e.target).data('model'); - if(!m) - return; - var s = m.get('stylable'); - if(!(s instanceof Array) && !s) - return; - this.onSelect(e, e.target); + e.stopPropagation(); + const model = $(e.target).data('model'); + model && this.editor.select(model); }, /** @@ -296,12 +294,11 @@ module.exports = { * @param {Object} el * @private * */ - onSelect(e, el) { - e.stopPropagation(); - var model = $(el).data('model'); + onSelect() { + const model = this.em.getSelected(); if (model) { - this.editor.select(model); + const el = model.view.el; this.showFixedElementOffset(el); this.hideElementOffset(); this.hideHighlighter();