mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
feat: add keyboard shortcut for redo (ctrl+shift+z)
This commit is contained in:
parent
32b9217bd2
commit
563aee81e1
4 changed files with 94 additions and 82 deletions
|
@ -36,9 +36,13 @@ const SHORTCUTS = {
|
||||||
shortcut: 'Modifier+F',
|
shortcut: 'Modifier+F',
|
||||||
label: translate('Search location'),
|
label: translate('Search location'),
|
||||||
},
|
},
|
||||||
CANCEL: {
|
UNDO: {
|
||||||
shortcut: 'Modifier+Z',
|
shortcut: 'Modifier+Z',
|
||||||
label: translate('Cancel edits'),
|
label: translate('Cancel last edit'),
|
||||||
|
},
|
||||||
|
REDO: {
|
||||||
|
shortcut: 'Modifier+Shift+Z',
|
||||||
|
label: translate('Redo last edit'),
|
||||||
},
|
},
|
||||||
PREVIEW: {
|
PREVIEW: {
|
||||||
shortcut: 'Modifier+E',
|
shortcut: 'Modifier+E',
|
||||||
|
|
|
@ -126,13 +126,22 @@ export class TopBar extends WithTemplate {
|
||||||
this.elements.undo.addEventListener('click', () => this._umap.undo())
|
this.elements.undo.addEventListener('click', () => this._umap.undo())
|
||||||
this.elements.undo.addEventListener('mouseover', () => {
|
this.elements.undo.addEventListener('mouseover', () => {
|
||||||
this._umap.tooltip.open({
|
this._umap.tooltip.open({
|
||||||
content: this._umap.help.displayLabel('CANCEL'),
|
content: this._umap.help.displayLabel('UNDO'),
|
||||||
anchor: this.elements.undo,
|
anchor: this.elements.undo,
|
||||||
position: 'bottom',
|
position: 'bottom',
|
||||||
delay: 500,
|
delay: 500,
|
||||||
duration: 5000,
|
duration: 5000,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
this.elements.redo.addEventListener('mouseover', () => {
|
||||||
|
this._umap.tooltip.open({
|
||||||
|
content: this._umap.help.displayLabel('REDO'),
|
||||||
|
anchor: this.elements.redo,
|
||||||
|
position: 'bottom',
|
||||||
|
delay: 500,
|
||||||
|
duration: 5000,
|
||||||
|
})
|
||||||
|
})
|
||||||
this.elements.view.addEventListener('click', () => this._umap.disableEdit())
|
this.elements.view.addEventListener('click', () => this._umap.disableEdit())
|
||||||
this.elements.view.addEventListener('mouseover', () => {
|
this.elements.view.addEventListener('mouseover', () => {
|
||||||
this._umap.tooltip.open({
|
this._umap.tooltip.open({
|
||||||
|
|
|
@ -499,8 +499,9 @@ export default class Umap {
|
||||||
}
|
}
|
||||||
|
|
||||||
initShortcuts() {
|
initShortcuts() {
|
||||||
const globalShortcuts = (event) => {
|
const shortcuts = {
|
||||||
if (event.key === 'Escape') {
|
Escape: {
|
||||||
|
do: () => {
|
||||||
if (this.importer.dialog.visible) {
|
if (this.importer.dialog.visible) {
|
||||||
this.importer.dialog.close()
|
this.importer.dialog.close()
|
||||||
} else if (this.editEnabled && this._leafletMap.editTools.drawing()) {
|
} else if (this.editEnabled && this._leafletMap.editTools.drawing()) {
|
||||||
|
@ -514,75 +515,72 @@ export default class Umap {
|
||||||
} else if (this.panel.isOpen()) {
|
} else if (this.panel.isOpen()) {
|
||||||
this.panel.close()
|
this.panel.close()
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
},
|
||||||
// From now on, only ctrl/meta shortcut
|
'Ctrl+f': {
|
||||||
if (!(event.ctrlKey || event.metaKey) || event.shiftKey) return
|
do: () => {
|
||||||
|
|
||||||
if (event.key === 'f') {
|
|
||||||
event.stopPropagation()
|
|
||||||
event.preventDefault()
|
|
||||||
this.search()
|
this.search()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'Ctrl+e': {
|
||||||
|
if: () => this.hasEditMode(),
|
||||||
|
do: () => {
|
||||||
|
console.log('doing')
|
||||||
|
if (!this.editEnabled) this.enableEdit()
|
||||||
|
else if (!this.isDirty) this.disableEdit()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'Ctrl+s': {
|
||||||
|
if: () => this.editEnabled && this.isDirty,
|
||||||
|
do: () => this.saveAll(),
|
||||||
|
},
|
||||||
|
'Ctrl+z': {
|
||||||
|
if: () => this.editEnabled && !Utils.isWritable(event.target),
|
||||||
|
do: () => this.sync._undoManager.undo(),
|
||||||
|
},
|
||||||
|
'Ctrl+Shift+Z': {
|
||||||
|
if: () => this.editEnabled && !Utils.isWritable(event.target),
|
||||||
|
do: () => this.sync._undoManager.redo(),
|
||||||
|
},
|
||||||
|
'Ctrl+m': {
|
||||||
|
if: () => this.editEnabled,
|
||||||
|
do: () => this._leafletMap.editTools.startMarker(),
|
||||||
|
},
|
||||||
|
'Ctrl+p': {
|
||||||
|
if: () => this.editEnabled,
|
||||||
|
do: () => this._leafletMap.editTools.startPolygon(),
|
||||||
|
},
|
||||||
|
'Ctrl+l': {
|
||||||
|
if: () => this.editEnabled,
|
||||||
|
do: () => this._leafletMap.editTools.startPolyline(),
|
||||||
|
},
|
||||||
|
'Ctrl+i': {
|
||||||
|
if: () => this.editEnabled,
|
||||||
|
do: () => this.importer.open(),
|
||||||
|
},
|
||||||
|
'Ctrl+o': {
|
||||||
|
if: () => this.editEnabled,
|
||||||
|
do: () => this.importer.openFiles(),
|
||||||
|
},
|
||||||
|
'Ctrl+h': {
|
||||||
|
if: () => this.editEnabled,
|
||||||
|
do: () => this.help.showGetStarted(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
const onKeyDown = (event) => {
|
||||||
|
const shiftKey = event.shiftKey ? 'Shift+' : ''
|
||||||
|
const altKey = event.altKey ? 'Alt+' : ''
|
||||||
|
const ctrlKey = event.ctrlKey || event.metaKey ? 'Ctrl+' : ''
|
||||||
|
const combination = `${ctrlKey}${shiftKey}${altKey}${event.key}`
|
||||||
|
|
||||||
/* Edit mode only shortcuts */
|
const shortcut = shortcuts[combination]
|
||||||
if (!this.hasEditMode()) return
|
if (shortcut && (!shortcut.if || shortcut.if())) {
|
||||||
|
shortcut.do()
|
||||||
// Edit mode Off
|
|
||||||
if (!this.editEnabled) {
|
|
||||||
switch (event.key) {
|
|
||||||
case 'e':
|
|
||||||
event.stopPropagation()
|
|
||||||
event.preventDefault()
|
|
||||||
this.enableEdit()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Edit mode on
|
|
||||||
let used = true
|
|
||||||
switch (event.key) {
|
|
||||||
case 'e':
|
|
||||||
if (!this.isDirty) this.disableEdit()
|
|
||||||
break
|
|
||||||
case 's':
|
|
||||||
if (this.isDirty) this.saveAll()
|
|
||||||
break
|
|
||||||
case 'z':
|
|
||||||
if (Utils.isWritable(event.target)) {
|
|
||||||
used = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
this.sync._undoManager.undo()
|
|
||||||
break
|
|
||||||
case 'm':
|
|
||||||
this._leafletMap.editTools.startMarker()
|
|
||||||
break
|
|
||||||
case 'p':
|
|
||||||
this._leafletMap.editTools.startPolygon()
|
|
||||||
break
|
|
||||||
case 'l':
|
|
||||||
this._leafletMap.editTools.startPolyline()
|
|
||||||
break
|
|
||||||
case 'i':
|
|
||||||
this.importer.open()
|
|
||||||
break
|
|
||||||
case 'o':
|
|
||||||
this.importer.openFiles()
|
|
||||||
break
|
|
||||||
case 'h':
|
|
||||||
this.help.showGetStarted()
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
used = false
|
|
||||||
}
|
|
||||||
if (used) {
|
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
document.addEventListener('keydown', globalShortcuts)
|
document.addEventListener('keydown', onKeyDown)
|
||||||
}
|
}
|
||||||
|
|
||||||
async initDataLayers(datalayers) {
|
async initDataLayers(datalayers) {
|
||||||
|
|
|
@ -117,6 +117,7 @@ export function escapeHTML(s) {
|
||||||
'dd',
|
'dd',
|
||||||
'b',
|
'b',
|
||||||
'i',
|
'i',
|
||||||
|
'kbd',
|
||||||
],
|
],
|
||||||
ADD_ATTR: [
|
ADD_ATTR: [
|
||||||
'target',
|
'target',
|
||||||
|
|
Loading…
Reference in a new issue