Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(views/geomap): add open location to blank item as well
Elian Doran6509acd6eeaf
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.tsindex 4430145720..161846dde6 100644--- a/apps/client/src/components/app_context.ts+++ b/apps/client/src/components/app_context.ts@@ -261,7 +261,6 @@ export type CommandMappings = {// GeomapdeleteFromMap: { noteId: string };- openGeoLocation: { noteId: string; event: JQuery.MouseDownEvent };toggleZenMode: CommandData;diff --git a/apps/client/src/services/link.ts b/apps/client/src/services/link.tsindex 41533647c6..107a9c9e3b 100644--- a/apps/client/src/services/link.ts+++ b/apps/client/src/services/link.ts@@ -277,13 +277,13 @@ function goToLink(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDownEvent) {return goToLinkExt(evt, hrefLink, $link);}-function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDownEvent | React.PointerEvent<HTMLCanvasElement>, hrefLink: string | undefined, $link?: JQuery<HTMLElement> | null) {+function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDownEvent | React.PointerEvent<HTMLCanvasElement> | null, hrefLink: string | undefined, $link?: JQuery<HTMLElement> | null) {if (hrefLink?.startsWith("data:")) {return true;}- evt.preventDefault();- evt.stopPropagation();+ evt?.preventDefault();+ evt?.stopPropagation();if (hrefLink && hrefLink.startsWith("#") && !hrefLink.startsWith("#root/") && $link) {if (handleAnchor(hrefLink, $link)) {@@ -293,14 +293,14 @@ function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDownEventconst { notePath, viewScope } = parseNavigationStateFromUrl(hrefLink);- const ctrlKey = utils.isCtrlKey(evt);- const shiftKey = evt.shiftKey;- const isLeftClick = "which" in evt && evt.which === 1;- const isMiddleClick = "which" in evt && evt.which === 2;+ const ctrlKey = evt && utils.isCtrlKey(evt);+ const shiftKey = evt?.shiftKey;+ const isLeftClick = !evt || ("which" in evt && evt.which === 1);+ const isMiddleClick = evt && "which" in evt && evt.which === 2;const targetIsBlank = ($link?.attr("target") === "_blank");const openInNewTab = (isLeftClick && ctrlKey) || isMiddleClick || targetIsBlank;const activate = (isLeftClick && ctrlKey && shiftKey) || (isMiddleClick && shiftKey);- const openInNewWindow = isLeftClick && evt.shiftKey && !ctrlKey;+ const openInNewWindow = isLeftClick && evt?.shiftKey && !ctrlKey;if (notePath) {if (openInNewWindow) {@@ -311,7 +311,7 @@ function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDownEventviewScope});} else if (isLeftClick) {- const ntxId = $(evt.target as any)+ const ntxId = $(evt?.target as any).closest("[data-ntx-id]").attr("data-ntx-id");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.tsindex 4eec358877..768a17d10a 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@@ -5,6 +5,7 @@ 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";+import link from "../../../services/link.js";export default function openContextMenu(noteId: string, e: LeafletMouseEvent) {contextMenu.show({@@ -13,7 +14,6 @@ export default function openContextMenu(noteId: string, e: LeafletMouseEvent) {items: [...buildGeoLocationItem(e),...linkContextMenu.getItems(),- { title: t("geo-map-context.open-location"), command: "openGeoLocation", uiIcon: "bx bx-map-alt" },{ title: "----" },{ title: t("geo-map-context.remove-from-map"), command: "deleteFromMap", uiIcon: "bx bx-trash" }],@@ -23,11 +23,6 @@ export default function openContextMenu(noteId: string, e: LeafletMouseEvent) {return;}- if (command === "openGeoLocation") {- appContext.triggerCommand(command, { noteId, event: e });- return;- }-// Pass the events to the link context menulinkContextMenu.handleLinkContextMenuItem(command, noteId);}@@ -48,7 +43,7 @@ export function openMapContextMenu(noteId: string, e: LeafletMouseEvent) {createNewNote(noteId, e);break;default:- appContext.triggerCommand(command);+ return;}}});@@ -62,8 +57,14 @@ function buildGeoLocationItem(e: LeafletMouseEvent) {return [{title: formatGeoLocation(e.latlng),+ uiIcon: "bx bx-current-location",handler: () => copyTextWithToast(formatGeoLocation(e.latlng, 15))},+ {+ title: t("geo-map-context.open-location"),+ uiIcon: "bx bx-map-alt",+ handler: () => link.goToLinkExt(null, `geo:${e.latlng.lat},${e.latlng.lng}`)+ },{title: "----"}diff --git a/apps/client/src/widgets/view_widgets/geo_view/index.ts b/apps/client/src/widgets/view_widgets/geo_view/index.tsindex e67768fce8..d68eb489aa 100644--- a/apps/client/src/widgets/view_widgets/geo_view/index.ts+++ b/apps/client/src/widgets/view_widgets/geo_view/index.ts@@ -294,17 +294,6 @@ export default class GeoView extends ViewMode<MapData> {this.#changeState(State.Normal);}- openGeoLocationEvent({ noteId, event }: EventData<"openGeoLocation">) {- const marker = this.currentMarkerData[noteId];- if (!marker) {- return;- }-- const latLng = this.currentMarkerData[noteId].getLatLng();- const url = `geo:${latLng.lat},${latLng.lng}`;- link.goToLinkExt(event, url);- }-deleteFromMapEvent({ noteId }: EventData<"deleteFromMap">) {moveMarker(noteId, null);}