Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ export default function(ctx) {
let currentModeName = null;
let currentMode = null;

const isLeftClick = (e) => {
const originalEvent = e?.originalEvent;
if (!originalEvent) { return true; }
if ('button' in originalEvent) { return originalEvent.button === 0; }
if ('buttons' in originalEvent) { return originalEvent.buttons === 1; }
return true;
};

events.drag = function(event, isDrag) {
if (isDrag({
point: event.point,
Expand Down Expand Up @@ -51,6 +59,7 @@ export default function(ctx) {
};

events.mousedown = function(event) {
if (!isLeftClick(event)) return;
mouseDownInfo = {
time: new Date().getTime(),
point: event.point
Expand All @@ -61,6 +70,7 @@ export default function(ctx) {
};

events.mouseup = function(event) {
if (!isLeftClick(event)) return;
const target = getFeaturesAndSetCursor(event, ctx);
event.featureTarget = target;

Expand Down
9 changes: 9 additions & 0 deletions test/interaction_events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ test('ensure user interactions fire right events', async (t) => {
], 'no unexpected draw events');
});

await t.test('right-click on the point does not select it', async () => {
// Now in `simple_select` mode with nothing selected ...
// Right-click should be ignored by Draw and not trigger any events.
map.fire('mousedown', makeMouseEvent(25, 25, { button: 2 }));
map.fire('mouseup', makeMouseEvent(25, 25, { button: 2 }));

assert.deepEqual(flushDrawEvents(), [], 'no draw events fired for right-click');
});

await t.test('re-select that point', async () => {
// Now in `simple_select` mode ...
// Move around, then click the existing point
Expand Down