diff --git a/src/editor/model/Editor.ts b/src/editor/model/Editor.ts index 617363560..3aac98110 100644 --- a/src/editor/model/Editor.ts +++ b/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) { diff --git a/test/specs/grapesjs/index.ts b/test/specs/grapesjs/index.ts index 32eab8d04..57747dea1 100644 --- a/test/specs/grapesjs/index.ts +++ b/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]);