mirror of
https://github.com/zadam/trilium.git
synced 2025-11-10 15:25:51 +01:00
feat(views/geomap): add open location to blank item as well
This commit is contained in:
@@ -261,7 +261,6 @@ export type CommandMappings = {
|
|||||||
|
|
||||||
// Geomap
|
// Geomap
|
||||||
deleteFromMap: { noteId: string };
|
deleteFromMap: { noteId: string };
|
||||||
openGeoLocation: { noteId: string; event: JQuery.MouseDownEvent };
|
|
||||||
|
|
||||||
toggleZenMode: CommandData;
|
toggleZenMode: CommandData;
|
||||||
|
|
||||||
|
|||||||
@@ -277,13 +277,13 @@ function goToLink(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDownEvent) {
|
|||||||
return goToLinkExt(evt, hrefLink, $link);
|
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:")) {
|
if (hrefLink?.startsWith("data:")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
evt.preventDefault();
|
evt?.preventDefault();
|
||||||
evt.stopPropagation();
|
evt?.stopPropagation();
|
||||||
|
|
||||||
if (hrefLink && hrefLink.startsWith("#") && !hrefLink.startsWith("#root/") && $link) {
|
if (hrefLink && hrefLink.startsWith("#") && !hrefLink.startsWith("#root/") && $link) {
|
||||||
if (handleAnchor(hrefLink, $link)) {
|
if (handleAnchor(hrefLink, $link)) {
|
||||||
@@ -293,14 +293,14 @@ function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDownEvent
|
|||||||
|
|
||||||
const { notePath, viewScope } = parseNavigationStateFromUrl(hrefLink);
|
const { notePath, viewScope } = parseNavigationStateFromUrl(hrefLink);
|
||||||
|
|
||||||
const ctrlKey = utils.isCtrlKey(evt);
|
const ctrlKey = evt && utils.isCtrlKey(evt);
|
||||||
const shiftKey = evt.shiftKey;
|
const shiftKey = evt?.shiftKey;
|
||||||
const isLeftClick = "which" in evt && evt.which === 1;
|
const isLeftClick = !evt || ("which" in evt && evt.which === 1);
|
||||||
const isMiddleClick = "which" in evt && evt.which === 2;
|
const isMiddleClick = evt && "which" in evt && evt.which === 2;
|
||||||
const targetIsBlank = ($link?.attr("target") === "_blank");
|
const targetIsBlank = ($link?.attr("target") === "_blank");
|
||||||
const openInNewTab = (isLeftClick && ctrlKey) || isMiddleClick || targetIsBlank;
|
const openInNewTab = (isLeftClick && ctrlKey) || isMiddleClick || targetIsBlank;
|
||||||
const activate = (isLeftClick && ctrlKey && shiftKey) || (isMiddleClick && shiftKey);
|
const activate = (isLeftClick && ctrlKey && shiftKey) || (isMiddleClick && shiftKey);
|
||||||
const openInNewWindow = isLeftClick && evt.shiftKey && !ctrlKey;
|
const openInNewWindow = isLeftClick && evt?.shiftKey && !ctrlKey;
|
||||||
|
|
||||||
if (notePath) {
|
if (notePath) {
|
||||||
if (openInNewWindow) {
|
if (openInNewWindow) {
|
||||||
@@ -311,7 +311,7 @@ function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDownEvent
|
|||||||
viewScope
|
viewScope
|
||||||
});
|
});
|
||||||
} else if (isLeftClick) {
|
} else if (isLeftClick) {
|
||||||
const ntxId = $(evt.target as any)
|
const ntxId = $(evt?.target as any)
|
||||||
.closest("[data-ntx-id]")
|
.closest("[data-ntx-id]")
|
||||||
.attr("data-ntx-id");
|
.attr("data-ntx-id");
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import linkContextMenu from "../../../menus/link_context_menu.js";
|
|||||||
import { t } from "../../../services/i18n.js";
|
import { t } from "../../../services/i18n.js";
|
||||||
import { createNewNote } from "./editing.js";
|
import { createNewNote } from "./editing.js";
|
||||||
import { copyTextWithToast } from "../../../services/clipboard_ext.js";
|
import { copyTextWithToast } from "../../../services/clipboard_ext.js";
|
||||||
|
import link from "../../../services/link.js";
|
||||||
|
|
||||||
export default function openContextMenu(noteId: string, e: LeafletMouseEvent) {
|
export default function openContextMenu(noteId: string, e: LeafletMouseEvent) {
|
||||||
contextMenu.show({
|
contextMenu.show({
|
||||||
@@ -13,7 +14,6 @@ export default function openContextMenu(noteId: string, e: LeafletMouseEvent) {
|
|||||||
items: [
|
items: [
|
||||||
...buildGeoLocationItem(e),
|
...buildGeoLocationItem(e),
|
||||||
...linkContextMenu.getItems(),
|
...linkContextMenu.getItems(),
|
||||||
{ title: t("geo-map-context.open-location"), command: "openGeoLocation", uiIcon: "bx bx-map-alt" },
|
|
||||||
{ title: "----" },
|
{ title: "----" },
|
||||||
{ title: t("geo-map-context.remove-from-map"), command: "deleteFromMap", uiIcon: "bx bx-trash" }
|
{ 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command === "openGeoLocation") {
|
|
||||||
appContext.triggerCommand(command, { noteId, event: e });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the events to the link context menu
|
// Pass the events to the link context menu
|
||||||
linkContextMenu.handleLinkContextMenuItem(command, noteId);
|
linkContextMenu.handleLinkContextMenuItem(command, noteId);
|
||||||
}
|
}
|
||||||
@@ -48,7 +43,7 @@ export function openMapContextMenu(noteId: string, e: LeafletMouseEvent) {
|
|||||||
createNewNote(noteId, e);
|
createNewNote(noteId, e);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
appContext.triggerCommand(command);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -62,8 +57,14 @@ function buildGeoLocationItem(e: LeafletMouseEvent) {
|
|||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
title: formatGeoLocation(e.latlng),
|
title: formatGeoLocation(e.latlng),
|
||||||
|
uiIcon: "bx bx-current-location",
|
||||||
handler: () => copyTextWithToast(formatGeoLocation(e.latlng, 15))
|
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: "----"
|
title: "----"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -294,17 +294,6 @@ export default class GeoView extends ViewMode<MapData> {
|
|||||||
this.#changeState(State.Normal);
|
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">) {
|
deleteFromMapEvent({ noteId }: EventData<"deleteFromMap">) {
|
||||||
moveMarker(noteId, null);
|
moveMarker(noteId, null);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user