Skip to content

Commit

Permalink
Ensure to deselect with undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Dec 11, 2023
1 parent 24f1d6a commit 9ef322b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/editor/model/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions test/specs/grapesjs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 9ef322b

Please sign in to comment.