Skip to content

Build your personal knowledge base with Trilium Notes

feat(client): clone the note from the note paths card header

Elian Doran0091b79c82a2
diff --git a/apps/client/src/widgets/ribbon/NotePathsTab.css b/apps/client/src/widgets/ribbon/NotePathsTab.css
index c06c9d62df..e8339a1370 100644
--- a/apps/client/src/widgets/ribbon/NotePathsTab.css
+++ b/apps/client/src/widgets/ribbon/NotePathsTab.css
@@ -8,12 +8,18 @@ body.experimental-feature-new-layout .note-paths-widget {
padding: 0;
list-style: none;
+ /* The room is for what the list is set between — the intro line, the clone link. Where it is
+ all the widget holds, as in the sidebar's card, the card's own padding is the room. */
+ &:first-child { margin-top: 0; }
+ &:last-child { margin-bottom: 0; }
+
/* A path is framed already by what holds the list — a card, or the mobile note menu — so it
carries no frame of its own: what tells one path from the next is the room around it, and
the gutter each hangs its marks in. */
li {
position: relative;
- padding: 5px 0 5px 17px;
+ padding-block: 5px;
+ padding-inline-start: 17px;
/* A path is read for where the note sits, not for the words themselves, so it is set a
step below the text around it — the separators and the marks with it, hence the size
on the path rather than on its links. */
@@ -27,7 +33,7 @@ body.experimental-feature-new-layout .note-paths-widget {
align-items: center;
content: "\ee8f";
top: 0;
- left: 0;
+ inset-inline-start: 0;
width: 12px;
bottom: 0;
font-family: "boxicons";
diff --git a/apps/client/src/widgets/ribbon/NotePathsTab.tsx b/apps/client/src/widgets/ribbon/NotePathsTab.tsx
index 7b8c630951..7313767b9a 100644
--- a/apps/client/src/widgets/ribbon/NotePathsTab.tsx
+++ b/apps/client/src/widgets/ribbon/NotePathsTab.tsx
@@ -18,9 +18,14 @@ export default function NotePathsTab({ note, hoistedNoteId, notePath }: TabConte
return <NotePathsWidget sortedNotePaths={sortedNotePaths} currentNotePath={notePath} />;
}
-export function NotePathsWidget({ sortedNotePaths, currentNotePath }: {
+export function NotePathsWidget({ sortedNotePaths, currentNotePath, cloneButton = true }: {
sortedNotePaths: NotePathRecord[] | undefined;
currentNotePath?: string | null | undefined;
+ /**
+ * Offer cloning the note below the list. Turned off by whoever offers it elsewhere — the sidebar's
+ * card puts the action in its header, where the widget's own buttons go.
+ */
+ cloneButton?: boolean;
}) {
const parentComponent = useContext(ParentComponent);
// What holds the list in the new layout — the sidebar's card, the mobile note menu's modal — is
@@ -46,10 +51,12 @@ export function NotePathsWidget({ sortedNotePaths, currentNotePath }: {
)) : undefined}
</ul>
- <LinkButton
- text={t("note_paths.clone_button")}
- onClick={() => parentComponent?.triggerCommand("cloneNoteIdsTo")}
- />
+ {cloneButton && (
+ <LinkButton
+ text={t("note_paths.clone_button")}
+ onClick={() => void parentComponent?.triggerCommand("cloneNoteIdsTo")}
+ />
+ )}
</>
</div>
);
diff --git a/apps/client/src/widgets/sidebar/NotePaths.tsx b/apps/client/src/widgets/sidebar/NotePaths.tsx
index b3969eddef..8c1a85a340 100644
--- a/apps/client/src/widgets/sidebar/NotePaths.tsx
+++ b/apps/client/src/widgets/sidebar/NotePaths.tsx
@@ -1,7 +1,11 @@
import "./NotePaths.css";
+import { useContext } from "preact/hooks";
+
import { t } from "../../services/i18n";
+import ActionButton from "../react/ActionButton";
import { useActiveNoteContext } from "../react/hooks";
+import { ParentComponent } from "../react/react_utils";
// The paths list is shared with the ribbon's note paths tab; only the framing differs here. The status
// bar's badge has no list of its own — it opens this one.
import { NotePathsWidget, useSortedNotePaths } from "../ribbon/NotePathsTab";
@@ -10,10 +14,24 @@ import RightPanelWidget from "./RightPanelWidget";
export default function NotePaths() {
const { note, notePath, hoistedNoteId } = useActiveNoteContext();
const sortedNotePaths = useSortedNotePaths(note, hoistedNoteId);
+ const parentComponent = useContext(ParentComponent);
return (
- <RightPanelWidget id="notePaths" title={t("note_paths.title")}>
- <NotePathsWidget sortedNotePaths={sortedNotePaths} currentNotePath={notePath} />
+ <RightPanelWidget
+ id="notePaths"
+ title={t("note_paths.title")}
+ // Cloning the note is what one does about its paths, so it sits where the card keeps what
+ // one does — its header — rather than as a line of its own below the list. The icon is the
+ // tree context menu's for the same action.
+ buttons={
+ <ActionButton
+ icon="bx bx-duplicate"
+ text={t("note_paths.clone_button")}
+ onClick={() => void parentComponent?.triggerCommand("cloneNoteIdsTo")}
+ />
+ }
+ >
+ <NotePathsWidget sortedNotePaths={sortedNotePaths} currentNotePath={notePath} cloneButton={false} />
</RightPanelWidget>
);
}