Skip to content

Commit a847c74

Browse files
committed
remove e.oldValue from e.value for plotly_selected event when shift key is down, fixes #1995
1 parent e36f056 commit a847c74

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

inst/htmlwidgets/plotly.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ HTMLWidgets.widget({
3737
if (!e) window.event;
3838
if (e.shiftKey) {
3939
x.highlight.persistent = true;
40+
x.highlight.persistentShift = true;
4041
} else {
4142
x.highlight.persistent = false;
43+
x.highlight.persistentShift = false;
4244
}
4345
};
4446

@@ -354,6 +356,17 @@ HTMLWidgets.widget({
354356

355357
var selectionChange = function(e) {
356358

359+
// Workaround for 'plotly_selected' now firing previously selected
360+
// points (in addition to new ones) when holding shift key. In our case,
361+
// we just want the new keys
362+
if (x.highlight.on === "plotly_selected" && x.highlight.persistentShift) {
363+
// https://stackoverflow.com/questions/1187518/how-to-get-the-difference-between-two-arrays-in-javascript
364+
Array.prototype.diff = function(a) {
365+
return this.filter(function(i) {return a.indexOf(i) < 0;});
366+
};
367+
e.value = e.value.diff(e.oldValue);
368+
}
369+
357370
// array of "event objects" tracking the selection history
358371
// this is used to avoid adding redundant selections
359372
var selectionHistory = crosstalk.var("plotlySelectionHistory").get() || [];

0 commit comments

Comments
 (0)