From 50d0b98be85ada87c71f342d39e147421cf82ce6 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Mon, 5 Nov 2018 17:50:15 -0800 Subject: [PATCH] Adds undo messages for connecting points to points, vertices, lines, and areas; and vertices to sibling and adjacent vertices Closes #1252 --- data/core.yaml | 16 ++++++++++++---- dist/locales/en.json | 18 ++++++++++++++---- modules/modes/drag_node.js | 24 ++++++++++++++++++++---- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index 045db64960..47324ad14f 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -118,10 +118,18 @@ en: annotation: Removed a member from a relation. connect: annotation: - point: Connected a way to a point. - vertex: Connected a way to another. - line: Connected a way to a line. - area: Connected a way to an area. + from_vertex: + to_point: Connected a way to a point. + to_vertex: Connected a way to another. + to_line: Connected a way to a line. + to_area: Connected a way to an area. + to_adjacent_vertex: Merged adjacent points in a way. + to_sibling_vertex: Connected a way to itself. + from_point: + to_point: Merged a point with another. + to_vertex: Merged a point with a point in a way. + to_line: Moved a point to a line. + to_area: Moved a point to an area. relation: These features can't be connected because they have conflicting relation roles. restriction: "These features can't be connected because it would damage a \"{relation}\" relation." disconnect: diff --git a/dist/locales/en.json b/dist/locales/en.json index bf5a470ffe..3fb3453395 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -154,10 +154,20 @@ }, "connect": { "annotation": { - "point": "Connected a way to a point.", - "vertex": "Connected a way to another.", - "line": "Connected a way to a line.", - "area": "Connected a way to an area." + "from_vertex": { + "to_point": "Connected a way to a point.", + "to_vertex": "Connected a way to another.", + "to_line": "Connected a way to a line.", + "to_area": "Connected a way to an area.", + "to_adjacent_vertex": "Merged adjacent points in a way.", + "to_sibling_vertex": "Connected a way to itself." + }, + "from_point": { + "to_point": "Merged a point with another.", + "to_vertex": "Merged a point with a point in a way.", + "to_line": "Moved a point to a line.", + "to_area": "Moved a point to an area." + } }, "relation": "These features can't be connected because they have conflicting relation roles.", "restriction": "These features can't be connected because it would damage a \"{relation}\" relation." diff --git a/modules/modes/drag_node.js b/modules/modes/drag_node.js index 0327ece067..518816881f 100644 --- a/modules/modes/drag_node.js +++ b/modules/modes/drag_node.js @@ -1,4 +1,5 @@ import _find from 'lodash-es/find'; +import _intersection from 'lodash-es/intersection'; import { event as d3_event, @@ -75,8 +76,23 @@ export function modeDragNode(context) { } - function connectAnnotation(entity) { - return t('operations.connect.annotation.' + entity.geometry(context.graph())); + function connectAnnotation(nodeEntity, targetEntity) { + var nodeGeometry = nodeEntity.geometry(context.graph()); + var targetGeometry = targetEntity.geometry(context.graph()); + if (nodeGeometry === 'vertex' && targetGeometry === 'vertex') { + var nodeParentWayIDs = context.graph().parentWays(nodeEntity); + var targetParentWayIDs = context.graph().parentWays(targetEntity); + var sharedParentWays = _intersection(nodeParentWayIDs, targetParentWayIDs); + // if both vertices are part of the same way + if (sharedParentWays.length !== 0) { + // if the nodes are next to each other, they are merged + if (sharedParentWays[0].areAdjacent(nodeEntity.id, targetEntity.id)) { + return t('operations.connect.annotation.from_vertex.to_adjacent_vertex'); + } + return t('operations.connect.annotation.from_vertex.to_sibling_vertex'); + } + } + return t('operations.connect.annotation.from_' + nodeGeometry + '.to_' + targetGeometry); } @@ -359,13 +375,13 @@ export function modeDragNode(context) { loc: choice.loc, edge: [target.nodes[choice.index - 1], target.nodes[choice.index]] }, entity), - connectAnnotation(target) + connectAnnotation(entity, target) ); } else if (target && target.type === 'node') { context.replace( actionConnect([target.id, entity.id]), - connectAnnotation(target) + connectAnnotation(entity, target) ); } else if (_wasMidpoint) {