Skip to content

Commit

Permalink
Fix viewport calculation when pasting
Browse files Browse the repository at this point in the history
(closes #311)
  • Loading branch information
bhousel committed Aug 25, 2021
1 parent d9e0755 commit 2b294d0
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions modules/behavior/paste.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,33 @@ export function behaviorPaste(context) {

d3_event.preventDefault();

var baseGraph = context.graph();
var startGraph = context.graph();
var mouse = context.map().mouse();
var projection = context.projection;
var viewport = new Extent(projection.clipExtent()).polygon();
var dimensions = projection.clipExtent();
var viewport = new Extent(dimensions[0], dimensions[1]).polygon();

if (!geomPointInPolygon(mouse, viewport)) return;

var oldIDs = context.copyIDs();
if (!oldIDs.length) return;

var extent = new Extent();
var oldGraph = context.copyGraph();
var copyGraph = context.copyGraph();
var newIDs = [];

var action = actionCopyEntities(oldIDs, oldGraph);
var action = actionCopyEntities(oldIDs, copyGraph);
context.perform(action);

var copies = action.copies();
var originals = new Set();
Object.values(copies).forEach(function(entity) { originals.add(entity.id); });

for (var id in copies) {
var oldEntity = oldGraph.entity(id);
var oldEntity = copyGraph.entity(id);
var newEntity = copies[id];

extent = extent.extend(oldEntity.extent(oldGraph));
extent = extent.extend(oldEntity.extent(copyGraph));

// Exclude child nodes from newIDs if their parent way was also copied.
var parents = context.graph().parentWays(newEntity);
Expand All @@ -58,7 +59,7 @@ export function behaviorPaste(context) {
var delta = vecSubtract(mouse, copyPoint);

context.perform(actionMove(newIDs, delta, projection));
context.enter(modeMove(context, newIDs, baseGraph));
context.enter(modeMove(context, newIDs, startGraph));
}


Expand Down

0 comments on commit 2b294d0

Please sign in to comment.