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

Adds feature to discard all the changes on the map #10045

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion dist/locales/en-GB.min.json

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion modules/core/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {


export function coreHistory(context) {
var dispatch = d3_dispatch('reset', 'change', 'merge', 'restore', 'undone', 'redone', 'storage_error');
var dispatch = d3_dispatch('reset', 'change', 'merge', 'restore', 'undone', 'redone', 'storage_error','discarded');
var lock = utilSessionMutex('lock');

// restorable if iD not open in another window/tab and a saved history exists in localStorage
Expand Down Expand Up @@ -197,6 +197,18 @@ export function coreHistory(context) {
return change(previous);
},

discard: function() {
d3_select(document).interrupt('history.perform');

var previousStack = _stack[_index];
var previous = previousStack.graph;

// Discards changes by reverting to the initial state of the map
_index = 0;
dispatch.call('discarded', this, _stack[_index], previousStack);
return change(previous);
},


// Back to the previous annotated state or _index = 0.
undo: function() {
Expand Down
1 change: 1 addition & 0 deletions modules/ui/intro/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export function helpHtml(id, replacements) {

// reference localized UI labels directly so that they'll always match
save: t.html('save.title'),
discard: t.html('discard.title'),
undo: t.html('undo.title'),
redo: t.html('redo.title'),
upload: t.html('commit.save'),
Expand Down
1 change: 1 addition & 0 deletions modules/ui/tools/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './modes';
export * from './notes';
export * from './save';
export * from './discard';
export * from './sidebar_toggle';
export * from './undo_redo';
25 changes: 19 additions & 6 deletions modules/ui/tools/undo_redo.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export function uiToolUndoRedo(context) {
return context.mode() && context.mode().id !== 'save' && context.map().editableDataEnabled(true /* ignore min zoom */);
}


tool.render = function(selection) {
var tooltipBehavior = uiTooltip()
.placement('bottom')
Expand All @@ -60,6 +59,9 @@ export function uiToolUndoRedo(context) {

var lastPointerUpType;

var longPressTimer;
var longPressFlag = false;

var buttons = selection.selectAll('button')
.data(commands)
.enter()
Expand All @@ -69,21 +71,32 @@ export function uiToolUndoRedo(context) {
// `pointerup` is always called before `click`
lastPointerUpType = d3_event.pointerType;
})
.on('click', function(d3_event, d) {
.on('mousedown', function(d3_event, d) {
d3_event.preventDefault();
if(d.id === 'undo'){
//logic to check for long-press of undo button
longPressTimer = setTimeout(function() {
longPressFlag = true;
context.history().discard();
}, 1000);
}

})
.on('mouseup', function(d3_event, d) {
var annotation = d.annotation();

if (editable() && annotation) {
if (editable() && annotation && !longPressFlag) {
d.action();
}

longPressFlag = false ;
clearTimeout(longPressTimer);

if (editable() && (
lastPointerUpType === 'touch' ||
lastPointerUpType === 'pen')
) {
// there are no tooltips for touch interactions so flash feedback instead

var label = annotation ?
t.append(d.id + '.tooltip', { action: annotation }) :
t.append(d.id + '.nothing');
Expand Down
5 changes: 3 additions & 2 deletions modules/ui/top_toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
} from 'd3-selection';

import _debounce from 'lodash-es/debounce';
import { uiToolDrawModes, uiToolNotes, uiToolSave, uiToolSidebarToggle, uiToolUndoRedo } from './tools';
import { uiToolDrawModes, uiToolNotes, uiToolSave, uiToolSidebarToggle, uiToolUndoRedo, uiToolDiscard } from './tools';


export function uiTopToolbar(context) {
Expand All @@ -12,7 +12,8 @@ export function uiTopToolbar(context) {
modes = uiToolDrawModes(context),
notes = uiToolNotes(context),
undoRedo = uiToolUndoRedo(context),
save = uiToolSave(context);
save = uiToolSave(context),
discard = uiToolDiscard(context);

function notesEnabled() {
var noteLayer = context.layers().layer('notes');
Expand Down