Skip to content

Commit

Permalink
Merge pull request #106 from renew-js/select-all
Browse files Browse the repository at this point in the history
Select all
  • Loading branch information
0x4d authored Apr 27, 2019
2 parents 5494ba2 + ca7d505 commit 21bb278
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/core/ElementRegistry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import BaseElementRegistry from 'diagram-js/lib/core/ElementRegistry';


export class ElementRegistry extends BaseElementRegistry {

constructor (props) {
super(props);
}

/**
* TODO: Remove hotfix for handles
* @return {*}[]
*/
getAll () {
return super.getAll().filter((element) => element.type !== 'handle');
}

}
2 changes: 1 addition & 1 deletion src/core/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ElementRegistry from 'diagram-js/lib/core/ElementRegistry';
import { ElementRegistry } from './ElementRegistry';
import { Canvas } from './Canvas';
import EventBusModule from './eventBus';
import CommandStackModule from './command';
Expand Down
15 changes: 15 additions & 0 deletions src/features/selection/behaviors/SelectAllBehavior.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Behavior } from '../../../core/eventBus/Behavior';


export class SelectAllBehavior extends Behavior {

constructor (selection) {
super();
this.selection = selection;
}

during (event) {
this.selection.selectAll();
}

}
2 changes: 2 additions & 0 deletions src/features/selection/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import OutlineModule from 'diagram-js/lib/features/outline';
import HandleModule from '../handle';
import OrientationModule from '../orientation';
import { SelectAllBehavior } from './behaviors/SelectAllBehavior';
import { SelectedBehavior } from './behaviors/SelectedBehavior';
import { SelectionAddBehavior } from './behaviors/SelectionAddBehavior';
import { SelectionClearBehavior } from './behaviors/SelectionClearBehavior';
Expand All @@ -21,6 +22,7 @@ export default {
'selection',
],
__behaviors__: [
[ 'select.all', SelectAllBehavior ],
[ 'selection.changed', SelectedBehavior ],
[ 'selection.clear', SelectionClearBehavior ],
[ 'selection.add', SelectionAddBehavior ],
Expand Down
7 changes: 6 additions & 1 deletion src/features/selection/providers/SelectionProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import { getBBox } from 'diagram-js/lib/util/Elements';

export class SelectionProvider extends Selection {

constructor (eventBus, selectionHandles) {
constructor (eventBus, selectionHandles, elementRegistry) {
super(eventBus);
this.eventBus = eventBus;
this.selectionHandles = selectionHandles;
this.elementRegistry = elementRegistry;
this.bbox = {};

this.selectionHandles.create(this.bbox);
}

selectAll () {
this.add(this.elementRegistry.getAll());
}

clear () {
this.select(null);
this.updateBBox();
Expand Down
21 changes: 21 additions & 0 deletions test/features/selection/Selection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ describe('modules/selection - Selection', () => {
});
});

it('should select all elements', function () {
expect(selection.count()).toBe(0);

selection.selectAll();

const count = canvas._elementRegistry.getAll().length;

expect(selection.count()).toBe(count - 1);
});

});

describe('Behavior', () => {
Expand All @@ -115,6 +125,17 @@ describe('modules/selection - Selection', () => {

expect(selection.count()).toBe(2);
});

it('should select all elements on select.all', function () {
expect(selection.count()).toBe(0);

eventBus.fire('select.all');

const count = canvas._elementRegistry.getAll().length;

expect(selection.count()).toBe(count - 1);
});

});

describe('Tools', () => {
Expand Down

0 comments on commit 21bb278

Please sign in to comment.