Merge pull request #1151 from umap-project/ctrl-shift-click

Document Shift-Click and add Ctrl-Shift-click to edit datalayer
This commit is contained in:
Yohan Boniface 2023-06-20 20:24:50 +02:00 committed by GitHub
commit 615498d3bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 6 deletions

View file

@ -172,7 +172,7 @@ L.U.ToggleEditAction = L.U.BaseFeatureAction.extend({
options: { options: {
toolbarIcon: { toolbarIcon: {
className: 'umap-toggle-edit', className: 'umap-toggle-edit',
tooltip: L._('Toggle edit mode (Shift+Click)'), tooltip: L._('Toggle edit mode (+Click)'),
}, },
}, },

View file

@ -333,8 +333,12 @@ L.U.FeatureMixin = {
this.view(e) this.view(e)
} else if (!this.isReadOnly()) { } else if (!this.isReadOnly()) {
if (e.originalEvent.shiftKey) { if (e.originalEvent.shiftKey) {
if (this._toggleEditing) this._toggleEditing(e) if (e.originalEvent.ctrlKey || e.originalEvent.metaKey) {
else this.edit(e) this.datalayer.edit(e)
} else {
if (this._toggleEditing) this._toggleEditing(e)
else this.edit(e)
}
} else { } else {
new L.Toolbar.Popup(e.latlng, { new L.Toolbar.Popup(e.latlng, {
className: 'leaflet-inplace-toolbar', className: 'leaflet-inplace-toolbar',
@ -389,7 +393,7 @@ L.U.FeatureMixin = {
let items = ['-'] let items = ['-']
if (this.map.editedFeature !== this) { if (this.map.editedFeature !== this) {
items.push({ items.push({
text: L._('Edit this feature'), text: L._('Edit this feature') + ' (⇧+Click)',
callback: this.edit, callback: this.edit,
context: this, context: this,
iconCls: 'umap-edit', iconCls: 'umap-edit',
@ -397,7 +401,7 @@ L.U.FeatureMixin = {
} }
items = items.concat( items = items.concat(
{ {
text: L._("Edit feature's layer"), text: L._("Edit feature's layer") + ' (Ctrl+⇧+Click)',
callback: this.datalayer.edit, callback: this.datalayer.edit,
context: this.datalayer, context: this.datalayer,
iconCls: 'umap-edit', iconCls: 'umap-edit',

View file

@ -64,6 +64,7 @@ L.U.UI = L.Evented.extend({
}, },
closePanel: function () { closePanel: function () {
this._panel.innerHTML = ''
this.resetPanelClassName() this.resetPanelClassName()
L.DomUtil.removeClass(this.parent, 'umap-ui') L.DomUtil.removeClass(this.parent, 'umap-ui')
this.fire('panel:closed') this.fire('panel:closed')

View file

@ -28,8 +28,21 @@ describe('L.U.FeatureMixin', function () {
assert.ok(qs('path[fill="DarkBlue"]')) // Polygon assert.ok(qs('path[fill="DarkBlue"]')) // Polygon
}) })
it('should take into account styles changes made in the datalayer', function () { it('should toggle edit panel on shift-clic', function () {
enableEdit() enableEdit()
happen.click(qs('path[fill="DarkBlue"]'), {shiftKey: true})
assert.ok(qs('form#umap-feature-properties'))
happen.click(qs('path[fill="DarkBlue"]'), {shiftKey: true})
assert.notOk(qs('form#umap-feature-properties'))
})
it('should open datalayer edit panel on ctrl-shift-clic', function () {
enableEdit()
happen.click(qs('path[fill="DarkBlue"]'), {shiftKey: true, ctrlKey: true})
assert.ok(qs('div.umap-layer-properties-container'))
})
it('should take into account styles changes made in the datalayer', function () {
happen.click( happen.click(
qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit') qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit')
) )