@@ -30,6 +30,7 @@ var doTicksSingle = require('./axes').doTicksSingle;
3030var getFromId = require ( './axis_ids' ) . getFromId ;
3131var prepSelect = require ( './select' ) . prepSelect ;
3232var clearSelect = require ( './select' ) . clearSelect ;
33+ var selectOnClick = require ( './select' ) . selectOnClick ;
3334var scaleZoom = require ( './scale_zoom' ) ;
3435
3536var constants = require ( './constants' ) ;
@@ -148,7 +149,11 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
148149 } ;
149150
150151 dragOptions . prepFn = function ( e , startX , startY ) {
152+ var dragModePrev = dragOptions . dragmode ;
151153 var dragModeNow = gd . _fullLayout . dragmode ;
154+ if ( dragModeNow !== dragModePrev ) {
155+ dragOptions . dragmode = dragModeNow ;
156+ }
152157
153158 recomputeAxisLists ( ) ;
154159
@@ -178,7 +183,19 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
178183 prepSelect ( e , startX , startY , dragOptions , dragModeNow ) ;
179184 } else {
180185 dragOptions . clickFn = clickFn ;
181- clearAndResetSelect ( ) ;
186+ if ( isSelectOrLasso ( dragModePrev ) ) {
187+ // TODO Fix potential bug
188+ // Note: clearing / resetting selection state only happens, when user
189+ // triggers at least one interaction in pan/zoom mode. Otherwise, the
190+ // select/lasso outlines are deleted (in plots.js.cleanPlot) but the selection
191+ // cache isn't cleared. So when the user switches back to select/lasso and
192+ // 'adds to a selection' with Shift, the "old", seemingly removed outlines
193+ // are redrawn again because the selection cache still holds their coordinates.
194+ // However, this isn't easily solved, since plots.js would need
195+ // to have a reference to the dragOptions object (which holds the
196+ // selection cache).
197+ clearAndResetSelect ( ) ;
198+ }
182199
183200 if ( ! allFixedRanges ) {
184201 if ( dragModeNow === 'zoom' ) {
@@ -207,12 +224,20 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
207224 }
208225
209226 function clickFn ( numClicks , evt ) {
227+ var clickmode = gd . _fullLayout . clickmode ;
228+
210229 removeZoombox ( gd ) ;
211230
212231 if ( numClicks === 2 && ! singleEnd ) doubleClick ( ) ;
213232
214233 if ( isMainDrag ) {
215- Fx . click ( gd , evt , plotinfo . id ) ;
234+ if ( clickmode . indexOf ( 'select' ) > - 1 ) {
235+ selectOnClick ( evt , gd , xaxes , yaxes , plotinfo . id , dragOptions ) ;
236+ }
237+
238+ if ( clickmode . indexOf ( 'event' ) > - 1 ) {
239+ Fx . click ( gd , evt , plotinfo . id ) ;
240+ }
216241 }
217242 else if ( numClicks === 1 && singleEnd ) {
218243 var ax = ns ? ya0 : xa0 ,
0 commit comments