mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add middle-button-drag to pan the workspace
This commit is contained in:
parent
7136dc1c72
commit
4fbf1fe780
@ -23,5 +23,6 @@ RED.state = {
|
|||||||
EXPORT: 6,
|
EXPORT: 6,
|
||||||
IMPORT: 7,
|
IMPORT: 7,
|
||||||
IMPORT_DRAGGING: 8,
|
IMPORT_DRAGGING: 8,
|
||||||
QUICK_JOINING: 9
|
QUICK_JOINING: 9,
|
||||||
|
PANNING: 10
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,8 @@ RED.view = (function() {
|
|||||||
lastClickNode = null,
|
lastClickNode = null,
|
||||||
dblClickPrimed = null,
|
dblClickPrimed = null,
|
||||||
clickTime = 0,
|
clickTime = 0,
|
||||||
clickElapsed = 0;
|
clickElapsed = 0,
|
||||||
|
scroll_position;
|
||||||
|
|
||||||
var clipboard = "";
|
var clipboard = "";
|
||||||
|
|
||||||
@ -73,6 +74,8 @@ RED.view = (function() {
|
|||||||
var PORT_TYPE_INPUT = 1;
|
var PORT_TYPE_INPUT = 1;
|
||||||
var PORT_TYPE_OUTPUT = 0;
|
var PORT_TYPE_OUTPUT = 0;
|
||||||
|
|
||||||
|
var chart = $("#chart");
|
||||||
|
|
||||||
var outer = d3.select("#chart")
|
var outer = d3.select("#chart")
|
||||||
.append("svg:svg")
|
.append("svg:svg")
|
||||||
.attr("width", space_width)
|
.attr("width", space_width)
|
||||||
@ -94,6 +97,16 @@ RED.view = (function() {
|
|||||||
.on("mousemove", canvasMouseMove)
|
.on("mousemove", canvasMouseMove)
|
||||||
.on("mousedown", canvasMouseDown)
|
.on("mousedown", canvasMouseDown)
|
||||||
.on("mouseup", canvasMouseUp)
|
.on("mouseup", canvasMouseUp)
|
||||||
|
.on("mouseenter", function() {
|
||||||
|
if (lasso) {
|
||||||
|
if (d3.event.buttons !== 1) {
|
||||||
|
lasso.remove();
|
||||||
|
lasso = null;
|
||||||
|
}
|
||||||
|
} else if (mouse_mode === RED.state.PANNING && d3.event.buttons !== 4) {
|
||||||
|
resetMouseVars();
|
||||||
|
}
|
||||||
|
})
|
||||||
.on("touchend", function() {
|
.on("touchend", function() {
|
||||||
clearTimeout(touchStartTime);
|
clearTimeout(touchStartTime);
|
||||||
touchStartTime = null;
|
touchStartTime = null;
|
||||||
@ -283,7 +296,6 @@ RED.view = (function() {
|
|||||||
function init() {
|
function init() {
|
||||||
|
|
||||||
RED.events.on("workspace:change",function(event) {
|
RED.events.on("workspace:change",function(event) {
|
||||||
var chart = $("#chart");
|
|
||||||
if (event.old !== 0) {
|
if (event.old !== 0) {
|
||||||
workspaceScrollPositions[event.old] = {
|
workspaceScrollPositions[event.old] = {
|
||||||
left:chart.scrollLeft(),
|
left:chart.scrollLeft(),
|
||||||
@ -526,6 +538,15 @@ RED.view = (function() {
|
|||||||
function canvasMouseDown() {
|
function canvasMouseDown() {
|
||||||
var point;
|
var point;
|
||||||
|
|
||||||
|
if (d3.event.button === 1) {
|
||||||
|
// Middle Click pan
|
||||||
|
mouse_mode = RED.state.PANNING;
|
||||||
|
mouse_position = [d3.event.pageX,d3.event.pageY]
|
||||||
|
scroll_position = [chart.scrollLeft(),chart.scrollTop()];
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!mousedown_node && !mousedown_link) {
|
if (!mousedown_node && !mousedown_link) {
|
||||||
selected_link = null;
|
selected_link = null;
|
||||||
updateSelection();
|
updateSelection();
|
||||||
@ -644,7 +665,6 @@ RED.view = (function() {
|
|||||||
function canvasMouseMove() {
|
function canvasMouseMove() {
|
||||||
var i;
|
var i;
|
||||||
var node;
|
var node;
|
||||||
mouse_position = d3.touches(this)[0]||d3.mouse(this);
|
|
||||||
// Prevent touch scrolling...
|
// Prevent touch scrolling...
|
||||||
//if (d3.touches(this)[0]) {
|
//if (d3.touches(this)[0]) {
|
||||||
// d3.event.preventDefault();
|
// d3.event.preventDefault();
|
||||||
@ -655,6 +675,22 @@ RED.view = (function() {
|
|||||||
//if (point[0]-container.scrollLeft < 30 && container.scrollLeft > 0) { container.scrollLeft -= 15; }
|
//if (point[0]-container.scrollLeft < 30 && container.scrollLeft > 0) { container.scrollLeft -= 15; }
|
||||||
//console.log(d3.mouse(this),container.offsetWidth,container.offsetHeight,container.scrollLeft,container.scrollTop);
|
//console.log(d3.mouse(this),container.offsetWidth,container.offsetHeight,container.scrollLeft,container.scrollTop);
|
||||||
|
|
||||||
|
if (mouse_mode === RED.state.PANNING) {
|
||||||
|
|
||||||
|
var pos = [d3.event.pageX,d3.event.pageY];
|
||||||
|
var deltaPos = [
|
||||||
|
mouse_position[0]-pos[0],
|
||||||
|
mouse_position[1]-pos[1]
|
||||||
|
];
|
||||||
|
|
||||||
|
chart.scrollLeft(scroll_position[0]+deltaPos[0])
|
||||||
|
chart.scrollTop(scroll_position[1]+deltaPos[1])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mouse_position = d3.touches(this)[0]||d3.mouse(this);
|
||||||
|
|
||||||
|
|
||||||
if (lasso) {
|
if (lasso) {
|
||||||
var ox = parseInt(lasso.attr("ox"));
|
var ox = parseInt(lasso.attr("ox"));
|
||||||
var oy = parseInt(lasso.attr("oy"));
|
var oy = parseInt(lasso.attr("oy"));
|
||||||
@ -906,6 +942,10 @@ RED.view = (function() {
|
|||||||
function canvasMouseUp() {
|
function canvasMouseUp() {
|
||||||
var i;
|
var i;
|
||||||
var historyEvent;
|
var historyEvent;
|
||||||
|
if (mouse_mode === RED.state.PANNING) {
|
||||||
|
resetMouseVars();
|
||||||
|
return
|
||||||
|
}
|
||||||
if (mouse_mode === RED.state.QUICK_JOINING) {
|
if (mouse_mode === RED.state.QUICK_JOINING) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user