Skip to content

Commit

Permalink
Ensure the resizer is applied on the proper selected component. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Sep 6, 2024
1 parent 9a6fa0c commit bc898c3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/core/src/commands/view/SelectComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,10 @@ export default {
*/
select(model: Component, event = {}) {
if (!model) return;
this.editor.select(model, { event, useValid: true });
this.initResize(model);
const { em } = this;
em.setSelected(model, { event, useValid: true });
// Ensure we're passing the proper selected component #6096
this.initResize(em.getSelected());
},

/**
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/dom_components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ export enum ComponentsEvents {
update = 'component:update',
updateInside = 'component:update-inside',

/**
* @event `component:select` Component selected.
* @example
* editor.on('component:select', (component) => { ... });
*/
select = 'component:select',
selectBefore = 'component:select:before',

/**
* @event `symbol:main:add` Added new main symbol.
* @example
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/editor/model/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { AddComponentsOption, ComponentAdd, DragMode } from '../../dom_component
import ComponentWrapper from '../../dom_components/model/ComponentWrapper';
import { CanvasSpotBuiltInTypes } from '../../canvas/model/CanvasSpot';
import DataSourceManager from '../../data_sources';
import { ComponentsEvents } from '../../dom_components/types';

Backbone.$ = $;

Expand Down Expand Up @@ -507,7 +508,7 @@ export default class EditorModel extends Model {

models.forEach((model) => {
if (model) {
this.trigger('component:select:before', model, opts);
this.trigger(ComponentsEvents.selectBefore, model, opts);

// Check for valid selectable
if (!model.get('selectable') || opts.abort) {
Expand Down Expand Up @@ -592,7 +593,7 @@ export default class EditorModel extends Model {
toDeselect.forEach((cmp) => this.removeSelected(cmp, opts));

selected.addComponent(model, opts);
this.trigger('component:select', model, opts);
this.trigger(ComponentsEvents.select, model, opts);
this.Canvas.addSpot({
type: CanvasSpotBuiltInTypes.Select,
component: model,
Expand Down

0 comments on commit bc898c3

Please sign in to comment.