1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Properly position quick-add dialog in all cases

Fixes #3781
This commit is contained in:
Nick O'Leary 2022-07-20 10:40:20 +01:00
parent 1b94cc3ac0
commit 5944fdb5dc
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 10 additions and 11 deletions

View File

@ -44,14 +44,10 @@ RED.contextMenu = (function () {
const canRemoveFromGroup = hasSelection && !!selection.nodes[0].g const canRemoveFromGroup = hasSelection && !!selection.nodes[0].g
const offset = $("#red-ui-workspace-chart").offset() const offset = $("#red-ui-workspace-chart").offset()
let addX = options.x - offset.left + $("#red-ui-workspace-chart").scrollLeft() // addX/addY must be the position in the workspace accounting for both scroll and scale
let addY = options.y - offset.top + $("#red-ui-workspace-chart").scrollTop() // The +5 is because we display the contextMenu -5,-5 to actual click position
let addX = (options.x + 5 - offset.left + $("#red-ui-workspace-chart").scrollLeft()) / RED.view.scale()
if (RED.view.snapGrid) { let addY = (options.y + 5 - offset.top + $("#red-ui-workspace-chart").scrollTop()) / RED.view.scale()
const gridSize = RED.view.gridSize()
addX = gridSize * Math.floor(addX / gridSize)
addY = gridSize * Math.floor(addY / gridSize)
}
const menuItems = [ const menuItems = [
{ onselect: 'core:show-action-list', onpostselect: function () { } }, { onselect: 'core:show-action-list', onpostselect: function () { } },

View File

@ -1071,12 +1071,15 @@ RED.view = (function() {
RED.view.redraw(); RED.view.redraw();
} }
// `point` is the place in the workspace the mouse has clicked.
// This takes into account scrolling and scaling of the workspace.
var ox = point[0]; var ox = point[0];
var oy = point[1]; var oy = point[1];
// Need to map that to browser location to position the pop-up
const offset = $("#red-ui-workspace-chart").offset() const offset = $("#red-ui-workspace-chart").offset()
var clientX = ox + offset.left - $("#red-ui-workspace-chart").scrollLeft() var clientX = (ox * scaleFactor) + offset.left - $("#red-ui-workspace-chart").scrollLeft()
var clientY = oy + offset.top - $("#red-ui-workspace-chart").scrollTop() var clientY = (oy * scaleFactor) + offset.top - $("#red-ui-workspace-chart").scrollTop()
if (RED.settings.get("editor").view['view-snap-grid']) { if (RED.settings.get("editor").view['view-snap-grid']) {
// eventLayer.append("circle").attr("cx",point[0]).attr("cy",point[1]).attr("r","2").attr('fill','red') // eventLayer.append("circle").attr("cx",point[0]).attr("cy",point[1]).attr("r","2").attr('fill','red')