Browse Source

Ensure to deselect with undefined

pull/5565/head
Artur Arseniev 2 years ago
parent
commit
9ef322b91b
  1. 8
      src/editor/model/Editor.ts
  2. 10
      test/specs/grapesjs/index.ts

8
src/editor/model/Editor.ts

@ -488,11 +488,11 @@ export default class EditorModel extends Model {
.filter(Boolean) as Component[];
const selected = this.getSelectedAll();
const mltSel = this.getConfig().multipleSelection;
// If an array is passed remove all selected
// expect those yet to be selected
const multiple = isArray(el);
multiple && this.removeSelected(selected.filter(s => !contains(models, s)));
if (multiple || !el) {
this.removeSelected(selected.filter(s => !contains(models, s)));
}
models.forEach(model => {
if (model) {

10
test/specs/grapesjs/index.ts

@ -505,6 +505,16 @@ describe('GrapesJS', () => {
expect(editor.getSelectedAll().length).toBe(0);
});
test('Deselect component', () => {
editor.select(el1);
expect(editor.getSelected()).toBe(el1);
expect(editor.getSelectedAll().length).toBe(1);
// Deselect with undefined
editor.select();
expect(editor.getSelected()).toBe(undefined);
expect(editor.getSelectedAll().length).toBe(0);
});
test('Select multiple components', () => {
// Select at first el1 and el3
editor.select([el1, el3]);

Loading…
Cancel
Save