Skip to content

Commit

Permalink
Show the edit menu when long-pressing or long-clicking (close #7577)
Browse files Browse the repository at this point in the history
  • Loading branch information
quincylvania committed May 9, 2020
1 parent 95dc16b commit 4a3fc57
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions modules/behavior/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function behaviorSelect(context) {
var _lastMouse = null;
var _showMenu = false;
var _p1 = null;
var _longPressTimeout;

// use pointer events on supported platforms; fallback to mouse events
var _pointerPrefix = 'PointerEvent' in window ? 'pointer' : 'mouse';
Expand All @@ -28,6 +29,8 @@ export function behaviorSelect(context) {


function keydown() {
if (_longPressTimeout) window.clearTimeout(_longPressTimeout);

var e = d3_event;
if (e && e.shiftKey) {
context.surface()
Expand All @@ -42,6 +45,8 @@ export function behaviorSelect(context) {


function keyup() {
if (_longPressTimeout) window.clearTimeout(_longPressTimeout);

var e = d3_event;
if (!e || !e.shiftKey) {
context.surface()
Expand All @@ -60,7 +65,29 @@ export function behaviorSelect(context) {
function pointerdown() {
if (!_p1) {
_p1 = point();

if (_longPressTimeout) window.clearTimeout(_longPressTimeout);

var node = this;

_longPressTimeout = window.setTimeout(function didLongPress() {
// simulate context menu event
if (window.CustomEvent) {
node.dispatchEvent(new CustomEvent('contextmenu'));
} else if (document.createEvent) {
var e = document.createEvent('HTMLEvents');
e.initEvent('contextmenu', true, false);
node.dispatchEvent(e);
} else { // IE
node.fireEvent('oncontextmenu');
}
}, 500);
}

if (d3_event) {
_lastMouse = d3_event;
}

d3_select(window)
.on(_pointerPrefix + 'up.select', pointerup, true);

Expand Down Expand Up @@ -102,6 +129,8 @@ export function behaviorSelect(context) {


function click() {
if (_longPressTimeout) window.clearTimeout(_longPressTimeout);

d3_select(window)
.on(_pointerPrefix + 'up.select', null, true);

Expand Down

0 comments on commit 4a3fc57

Please sign in to comment.