diff --git a/apps/client/src/widgets/view_widgets/geo_view/context_menu.ts b/apps/client/src/widgets/view_widgets/geo_view/context_menu.ts index 331beac05..4eec35887 100644 --- a/apps/client/src/widgets/view_widgets/geo_view/context_menu.ts +++ b/apps/client/src/widgets/view_widgets/geo_view/context_menu.ts @@ -1,17 +1,17 @@ import type { LatLng, LeafletMouseEvent } from "leaflet"; import appContext from "../../../components/app_context.js"; -import type { ContextMenuEvent } from "../../../menus/context_menu.js"; import contextMenu from "../../../menus/context_menu.js"; import linkContextMenu from "../../../menus/link_context_menu.js"; import { t } from "../../../services/i18n.js"; import { createNewNote } from "./editing.js"; import { copyTextWithToast } from "../../../services/clipboard_ext.js"; -export default function openContextMenu(noteId: string, e: ContextMenuEvent) { +export default function openContextMenu(noteId: string, e: LeafletMouseEvent) { contextMenu.show({ - x: e.pageX, - y: e.pageY, + x: e.originalEvent.pageX, + y: e.originalEvent.pageY, items: [ + ...buildGeoLocationItem(e), ...linkContextMenu.getItems(), { title: t("geo-map-context.open-location"), command: "openGeoLocation", uiIcon: "bx bx-map-alt" }, { title: "----" }, @@ -39,10 +39,7 @@ export function openMapContextMenu(noteId: string, e: LeafletMouseEvent) { x: e.originalEvent.pageX, y: e.originalEvent.pageY, items: [ - { - title: formatGeoLocation(e.latlng), - handler: () => copyTextWithToast(formatGeoLocation(e.latlng, 15)) - }, + ...buildGeoLocationItem(e), { title: t("geo-map-context.add-note"), command: "addNoteToMap", uiIcon: "bx bx-plus" } ], selectMenuItemHandler: ({ command }) => { @@ -57,6 +54,18 @@ export function openMapContextMenu(noteId: string, e: LeafletMouseEvent) { }); } -function formatGeoLocation(latlng: LatLng, precision: number = 6) { - return `${latlng.lat.toFixed(precision)}, ${latlng.lng.toFixed(precision)}`; +function buildGeoLocationItem(e: LeafletMouseEvent) { + function formatGeoLocation(latlng: LatLng, precision: number = 6) { + return `${latlng.lat.toFixed(precision)}, ${latlng.lng.toFixed(precision)}`; + } + + return [ + { + title: formatGeoLocation(e.latlng), + handler: () => copyTextWithToast(formatGeoLocation(e.latlng, 15)) + }, + { + title: "----" + } + ]; } diff --git a/apps/client/src/widgets/view_widgets/geo_view/markers.ts b/apps/client/src/widgets/view_widgets/geo_view/markers.ts index ca4170f6e..8853734ec 100644 --- a/apps/client/src/widgets/view_widgets/geo_view/markers.ts +++ b/apps/client/src/widgets/view_widgets/geo_view/markers.ts @@ -33,7 +33,7 @@ export default function processNoteWithMarker(map: Map, note: FNote, location: s } }); newMarker.on("contextmenu", (e) => { - openContextMenu(note.noteId, e.originalEvent); + openContextMenu(note.noteId, e); }); const el = newMarker.getElement();