From b11b33e3ab0b7dbda4da1cbdbb62c49b7d98708a Mon Sep 17 00:00:00 2001 From: fredj Date: Wed, 7 Dec 2011 15:03:39 +0100 Subject: [PATCH] SelectFeature stops selecting features after a right click on the map --- lib/OpenLayers/Handler/Feature.js | 8 +- tests/manual/select-feature-right-click.html | 86 ++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 tests/manual/select-feature-right-click.html diff --git a/lib/OpenLayers/Handler/Feature.js b/lib/OpenLayers/Handler/Feature.js index d4c65e7872..f2e9741a2a 100644 --- a/lib/OpenLayers/Handler/Feature.js +++ b/lib/OpenLayers/Handler/Feature.js @@ -173,7 +173,13 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, { * evt - {Event} */ mousedown: function(evt) { - this.down = evt.xy; + // Feature selection is only done with a left click. Other handlers may stop the + // propagation of left-click mousedown events but not right-click mousedown events. + // This mismatch causes problems when comparing the location of the down and up + // events in the click function so it is important ignore right-clicks. + if (OpenLayers.Event.isLeftClick(evt) || OpenLayers.Event.isSingleTouch(evt)) { + this.down = evt.xy; + } return this.handle(evt) ? !this.stopDown : true; }, diff --git a/tests/manual/select-feature-right-click.html b/tests/manual/select-feature-right-click.html new file mode 100644 index 0000000000..edd79d66c3 --- /dev/null +++ b/tests/manual/select-feature-right-click.html @@ -0,0 +1,86 @@ + + + OpenLayers Ticket 3404 + + + + + + + + +
+

Ticket 3404 Test Page

+

This bug is only triggered by physical right mouse clicks so it is not possible to write + an automated js unit test

+

When a SelectFeature control and a Navigation control are added to a map the left-click + mousedown events are stopped by a Drag handler before reaching the Feature handler. However, + right-click mousedown events so pass through and reach the Feature handler.

+

The Feature handler records the xy of + each mousedown and mouseup events so they can be compared in the click event. Because only right-click + mousedown event are received the location of future left-click mouseup events are compared + to the location of the 'stale' right-click mousedown event resulting in the feature not being selected.

+

Steps to recreate the bug: +

    +
  1. Left-click a point to select it.
  2. +
  3. Left-click the map to deselect the point.
  4. +
  5. Left-click a different point to select it.
  6. +
  7. Left-click the map to deselect the second point.
  8. +
  9. Right-click the map then left-click to close the browser context menu.
  10. +
  11. Left-click a point.
  12. +
+

+

Expected: The point is selected.

+
+
+
+ + + +