Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cycle road tag hotkey #6333

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ en:
description: Make this line go in the opposite direction.
key: V
annotation: Reversed a line.
cycle_highway_tag:
title: Cycle Highway Tag
description: Shortcut to cycle selected highway through several different tags.
key: C
annotation: Changed highway tag of selected way.
restriction: This operation is only permitted for highways and untagged lines.
split:
title: Split
description:
Expand Down Expand Up @@ -1855,6 +1861,7 @@ en:
reflect_long: "Reflect features across the longer axis"
reflect_short: "Reflect features across the shorter axis"
delete: "Delete selected features"
cycle_highway_tag: "Change selected road type"
commands:
title: "Commands"
copy: "Copy selected features"
Expand Down
5 changes: 5 additions & 0 deletions data/shortcuts.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@
"modifiers": ["⌘"],
"shortcuts": ["⌫"],
"text": "shortcuts.editing.operations.delete"
},
{
"modifiers": ["⇧"],
"shortcuts": ["operations.cycle_highway_tag.key"],
"text": "shortcuts.editing.operations.cycle_highway_tag"
}
]
}
Expand Down
5 changes: 5 additions & 0 deletions modules/core/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ export function coreHistory(context) {
},


peekAnnotation: function() {
return _stack[_index].annotation;
},


merge: function(entities, extent) {
var stack = _stack.map(function(state) { return state.graph; });
_stack[0].graph.rebase(entities, stack, false);
Expand Down
75 changes: 75 additions & 0 deletions modules/operations/cycle_highway_tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { t } from '../util/locale';
import { actionChangeTags } from '../actions/index';
import { behaviorOperation } from '../behavior/index';


export function operationCycleHighwayTag(selectedIDs, context) {
var _entityID = selectedIDs[0];
var _entity = context.entity(_entityID);
var _prevSelectedIDs;
var ROAD_TYPES = ['residential', 'service', 'track', 'unclassified', 'tertiary'];


var updateHighwayTag = function (tags) {
var idx = tags.highway ? ROAD_TYPES.indexOf(tags.highway) : -1;
tags.highway = ROAD_TYPES[(idx + 1) % ROAD_TYPES.length];
};


var operation = function() {
_entity = context.entity(_entityID);
// Calculate whether the changes since the last time this action ran
// are only to highway tags.
if (_prevSelectedIDs) {
var sameSelection = _prevSelectedIDs ? _prevSelectedIDs[0] === selectedIDs[0] : false;
}

var tags = Object.assign({}, _entity.tags);
updateHighwayTag(tags);

_prevSelectedIDs = selectedIDs;

// context peeking tells us the last operation performed. Was it cycle road tags?
if (sameSelection && context.history().peekAnnotation() === operation.annotation()) {
// Coalesce the update of Highway type tags into the previous tag change
context.replace(actionChangeTags(_entityID, tags), operation.annotation());
} else {
context.perform(actionChangeTags(_entityID, tags), operation.annotation());
}
};


operation.available = function() {
return selectedIDs.length === 1 &&
_entity.type === 'way' &&
new Set(_entity.nodes).size > 1;
};


operation.disabled = function() {
if ( Object.keys(_entity.tags).length > 0 && !_entity.tags.highway) {
return 'restriction';
}
};


operation.tooltip = function() {
var disable = operation.disabled();
return disable ?
t('operations.cycle_highway_tag.' + disable) :
t('operations.cycle_highway_tag.description');
};


operation.annotation = function() {
return t('operations.cycle_highway_tag.annotation');
};


operation.id = 'cycle_highway_tag';
operation.keys = ['⇧' + t('operations.cycle_highway_tag.key')];
operation.title = t('operations.cycle_highway_tag.title');
operation.behavior = behaviorOperation(context).which(operation);

return operation;
}
1 change: 1 addition & 0 deletions modules/operations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export { operationReverse } from './reverse';
export { operationRotate } from './rotate';
export { operationSplit } from './split';
export { operationStraighten } from './straighten';
export { operationCycleHighwayTag } from './cycle_highway_tag';