Skip to content

Build your personal knowledge base with Trilium Notes

feat(views/geomap): dragging notes that are not children

Elian Doran63c408c45b6d
diff --git a/apps/client/src/widgets/view_widgets/geo_view/dragging.ts b/apps/client/src/widgets/view_widgets/geo_view/dragging.ts
index df056aad53..bc1b0aa974 100644
--- a/apps/client/src/widgets/view_widgets/geo_view/dragging.ts
+++ b/apps/client/src/widgets/view_widgets/geo_view/dragging.ts
@@ -1,13 +1,15 @@
import type { Map } from "leaflet";
import type { DragData } from "../../note_tree.js";
import { moveMarker } from "./editing";
+import froca from "../../../services/froca.js";
+import branches from "../../../services/branches.js";
-export default function setupDragging($container: JQuery<HTMLElement>, map: Map) {
+export default function setupDragging($container: JQuery<HTMLElement>, map: Map, mapNoteId: string) {
$container.on("dragover", (e) => {
// Allow drag.
e.preventDefault();
});
- $container.on("drop", (e) => {
+ $container.on("drop", async (e) => {
if (!e.originalEvent) {
return;
}
@@ -30,7 +32,15 @@ export default function setupDragging($container: JQuery<HTMLElement>, map: Map)
var y = e.originalEvent.clientY - (offset?.top ?? 0);
const latlng = map.containerPointToLatLng([ x, y ]);
- moveMarker(noteId, latlng);
+
+ const note = await froca.getNote(noteId, true);
+ const parents = note?.getParentNoteIds();
+ if (parents?.includes(mapNoteId)) {
+ await moveMarker(noteId, latlng);
+ } else {
+ await branches.cloneNoteToParentNote(noteId, mapNoteId);
+ await moveMarker(noteId, latlng);
+ }
} catch (e) {
console.warn(e);
}
diff --git a/apps/client/src/widgets/view_widgets/geo_view/index.ts b/apps/client/src/widgets/view_widgets/geo_view/index.ts
index ebb0606938..3181773d83 100644
--- a/apps/client/src/widgets/view_widgets/geo_view/index.ts
+++ b/apps/client/src/widgets/view_widgets/geo_view/index.ts
@@ -159,7 +159,7 @@ export default class GeoView extends ViewMode<MapData> {
map.on("zoomend", updateFn);
map.on("click", (e) => this.#onMapClicked(e))
map.on("contextmenu", (e) => openMapContextMenu(this.parentNote.noteId, e));
- setupDragging(this.$container, map);
+ setupDragging(this.$container, map, this.parentNote.noteId);
this.#reloadMarkers();