mirror of https://github.com/node-red/node-red.git
Add grab/grabbing cursor for spacebar pan mode
- Show grab cursor (open hand) when spacebar is pressed - Show grabbing cursor (closed hand) when actively panning with spacebar+drag - Revert to grab cursor on mouse release if spacebar still held - Clear cursor when spacebar is released - Apply cursor to SVG element (outer) where mouse events occur - Handle edge cases: window blur, canvas blur, spacebar release outside canvaspan-zoom
parent
47026ec744
commit
775d6181c9
|
|
@ -632,8 +632,12 @@ RED.view = (function() {
|
||||||
|
|
||||||
if (e.type === "keydown" && !spacebarPressed) {
|
if (e.type === "keydown" && !spacebarPressed) {
|
||||||
spacebarPressed = true;
|
spacebarPressed = true;
|
||||||
|
// Change cursor to grab hand when spacebar is pressed
|
||||||
|
outer.style('cursor', 'grab');
|
||||||
} else if (e.type === "keyup" && spacebarPressed) {
|
} else if (e.type === "keyup" && spacebarPressed) {
|
||||||
spacebarPressed = false;
|
spacebarPressed = false;
|
||||||
|
// Revert cursor when spacebar is released
|
||||||
|
outer.style('cursor', '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -642,6 +646,8 @@ RED.view = (function() {
|
||||||
function handleWindowSpacebarUp(e) {
|
function handleWindowSpacebarUp(e) {
|
||||||
if ((e.keyCode === 32 || e.key === ' ') && spacebarPressed) {
|
if ((e.keyCode === 32 || e.key === ' ') && spacebarPressed) {
|
||||||
spacebarPressed = false;
|
spacebarPressed = false;
|
||||||
|
// Revert cursor when spacebar is released outside canvas
|
||||||
|
outer.style('cursor', '');
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
@ -656,6 +662,8 @@ RED.view = (function() {
|
||||||
window.addEventListener("blur", function() {
|
window.addEventListener("blur", function() {
|
||||||
if (spacebarPressed) {
|
if (spacebarPressed) {
|
||||||
spacebarPressed = false;
|
spacebarPressed = false;
|
||||||
|
// Revert cursor when window loses focus
|
||||||
|
outer.style('cursor', '');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -1114,6 +1122,8 @@ RED.view = (function() {
|
||||||
// Reset spacebar state when chart loses focus to prevent stuck state
|
// Reset spacebar state when chart loses focus to prevent stuck state
|
||||||
if (spacebarPressed) {
|
if (spacebarPressed) {
|
||||||
spacebarPressed = false;
|
spacebarPressed = false;
|
||||||
|
// Revert cursor when chart loses focus
|
||||||
|
outer.style('cursor', '');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1582,6 +1592,8 @@ RED.view = (function() {
|
||||||
mouse_mode = RED.state.PANNING;
|
mouse_mode = RED.state.PANNING;
|
||||||
mouse_position = [d3.event.pageX,d3.event.pageY]
|
mouse_position = [d3.event.pageX,d3.event.pageY]
|
||||||
scroll_position = [chart.scrollLeft(),chart.scrollTop()];
|
scroll_position = [chart.scrollLeft(),chart.scrollTop()];
|
||||||
|
// Change cursor to grabbing while actively panning
|
||||||
|
outer.style('cursor', 'grabbing');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2497,6 +2509,12 @@ RED.view = (function() {
|
||||||
}
|
}
|
||||||
if (mouse_mode === RED.state.PANNING) {
|
if (mouse_mode === RED.state.PANNING) {
|
||||||
resetMouseVars();
|
resetMouseVars();
|
||||||
|
// Revert to grab cursor if spacebar still held, otherwise clear cursor
|
||||||
|
if (spacebarPressed) {
|
||||||
|
outer.style('cursor', 'grab');
|
||||||
|
} else {
|
||||||
|
outer.style('cursor', '');
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (mouse_mode === RED.state.SELECTING_NODE) {
|
if (mouse_mode === RED.state.SELECTING_NODE) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue