Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass along mode to BrushEvent #75

Merged
merged 9 commits into from
Aug 26, 2020
24 changes: 12 additions & 12 deletions src/brush.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,21 +305,21 @@ function brush(dim) {
if (++this.active === 1) this.state.emitter = this, this.starting = true;
return this;
},
start: function() {
if (this.starting) this.starting = false, this.emit("start");
else this.emit("brush");
start: function(mode) {
if (this.starting) this.starting = false, this.emit("start", mode);
else this.emit("brush", mode);
return this;
},
brush: function() {
this.emit("brush");
brush: function(mode) {
this.emit("brush", mode);
return this;
},
end: function() {
if (--this.active === 0) delete this.state.emitter, this.emit("end");
end: function(mode) {
if (--this.active === 0) delete this.state.emitter, this.emit("end", mode);
return this;
},
emit: function(type) {
customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
emit: function(type, mode) {
customEvent(new BrushEvent(brush, type, dim.output(this.state.selection), mode), listeners.apply, listeners, [type, this.that, this.args]);
}
};

Expand Down Expand Up @@ -391,7 +391,7 @@ function brush(dim) {
nopropagation();
interrupt(that);
redraw.call(that);
emit.start();
emit.start(mode.name);

function moved() {
var point1 = pointer(that);
Expand Down Expand Up @@ -456,7 +456,7 @@ function brush(dim) {
|| selection[1][1] !== s1) {
state.selection = [[w1, n1], [e1, s1]];
redraw.call(that);
emit.brush();
emit.brush(mode.name);
}
}

Expand All @@ -474,7 +474,7 @@ function brush(dim) {
overlay.attr("cursor", cursors.overlay);
if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
if (empty(selection)) state.selection = null, redraw.call(that);
emit.end();
emit.end(mode.name);
}

function keydowned() {
Expand Down
3 changes: 2 additions & 1 deletion src/event.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default function(target, type, selection) {
export default function(target, type, selection, mode) {
this.target = target;
this.type = type;
this.selection = selection;
this.mode = mode;
}