Skip to content

Commit

Permalink
accumulate selected nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ni55aN committed Aug 8, 2018
1 parent 4df9529 commit dc8d58d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class NodeEditor extends Context {
window.addEventListener('keyup', e => this.trigger('keyup', e));
this.on('nodecreated', node => this.getComponent(node.name).created(node));
this.on('noderemoved', node => this.getComponent(node.name).destroyed(node));
this.on('selectnode', node => this.selectNode(node));
this.on('selectnode', ({ node, accumulate }) => this.selectNode(node, accumulate));
}

addNode(node: Node) {
Expand Down Expand Up @@ -72,13 +72,13 @@ export class NodeEditor extends Context {
}

selectNode(node: Node, accumulate: boolean = false) {
if (this.nodes.indexOf(node) === -1)
if (this.nodes.indexOf(node) === -1)
throw new Error('Node not exist in list');

if (!this.trigger('nodeselect', node)) return;

this.selected.add(node, accumulate);

this.selected.add(node, accumulate);

this.trigger('nodeselected', node);
}

Expand Down
11 changes: 6 additions & 5 deletions src/view/drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Drag {
e.stopPropagation();
this.mouseStart = this.getCoords(e);

this.onStart();
this.onStart(e);
}

move(e) {
Expand All @@ -45,12 +45,13 @@ export class Drag {
let delta = [x - this.mouseStart[0], y - this.mouseStart[1]];
let zoom = this.el.getBoundingClientRect().width / this.el.offsetWidth;

this.onTranslate(delta[0] / zoom, delta[1] / zoom);
this.onTranslate(delta[0] / zoom, delta[1] / zoom, e);
}

up() {
up(e) {
if (!this.mouseStart) return;

this.mouseStart = null;

this.onDrag();
this.onDrag(e);
}
}
12 changes: 7 additions & 5 deletions src/view/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export class Node extends Emitter {
return this.sockets.get(io).getPosition(this.node);
}

onSelect() {
onSelect(e) {
this._startPosition = [...this.node.position];
this.trigger('selectnode', this.node);
this.trigger('selectnode', { node: this.node, accumulate: e.ctrlKey });
}

onTranslate(dx, dy) {
Expand All @@ -63,11 +63,13 @@ export class Node extends Emitter {

if (!this.trigger('nodetranslate', params)) return;

this.node.position[0] = params.x;
this.node.position[1] = params.y;
const prev = [...node.position];

node.position[0] = params.x;
node.position[1] = params.y;

this.update();
this.trigger('nodetranslated', { node });
this.trigger('nodetranslated', { node, prev });
}

update() {
Expand Down

0 comments on commit dc8d58d

Please sign in to comment.