From 9858fc2190e473f7b357f70076a8824f5fe81b48 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Tue, 25 Feb 2025 17:17:49 +0100 Subject: [PATCH] fix: make sure we sync a line when hitting esc while drawing I first tried to handle this on Leaflet.Editable side, to make it fire the "editable:edited" event we use to trigger the sync, but deciding what to do with a feature on escape needs some decisions that seems hard to implement in a generic way in Leaflet.Editable. We call stopDrawing, which then calls cancelDrawing, so here one need to decide if cancelDrawing should keep the already drawn line (but cancel the point being drawn) or cancel everything. This is why I end up making this change in uMap itself. --- umap/static/umap/js/umap.controls.js | 1 + umap/tests/integration/test_websocket_sync.py | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index e3ee563f..287ca885 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -699,6 +699,7 @@ U.Editable = L.Editable.extend({ if (!event.layer.feature.hasGeom()) { event.layer.feature.del() } else { + event.layer.feature.onCommit() event.layer.feature.edit() } }) diff --git a/umap/tests/integration/test_websocket_sync.py b/umap/tests/integration/test_websocket_sync.py index 4f081ed2..96489dfa 100644 --- a/umap/tests/integration/test_websocket_sync.py +++ b/umap/tests/integration/test_websocket_sync.py @@ -604,3 +604,25 @@ def test_should_sync_saved_status(new_page, asgi_live_server, tilelayer): # Peer A should not be in dirty state expect(peerA.locator("body")).not_to_have_class(re.compile(".*umap-is-dirty.*")) + + +@pytest.mark.xdist_group(name="websockets") +def test_should_sync_line_on_escape(new_page, asgi_live_server, tilelayer): + map = MapFactory(name="sync", edit_status=Map.ANONYMOUS) + map.settings["properties"]["syncEnabled"] = True + map.save() + + # Create two tabs + peerA = new_page("Page A") + peerA.goto(f"{asgi_live_server.url}{map.get_absolute_url()}?edit") + peerB = new_page("Page B") + peerB.goto(f"{asgi_live_server.url}{map.get_absolute_url()}?edit") + + # Create a new marker from peerA + peerA.get_by_title("Draw a polyline").click() + peerA.locator("#map").click(position={"x": 220, "y": 220}) + peerA.locator("#map").click(position={"x": 200, "y": 200}) + peerA.locator("body").press("Escape") + + expect(peerA.locator("path")).to_have_count(1) + expect(peerB.locator("path")).to_have_count(1)