Skip to content

Build your personal knowledge base with Trilium Notes

feat(attributes): give a phone a way to paste, in the header that always stands

Elian Doran5194c419bf37
diff --git a/apps/client/src/widgets/sidebar/AttributeList.mobile.spec.tsx b/apps/client/src/widgets/sidebar/AttributeList.mobile.spec.tsx
index ef1386ebc0..4cfdd7e12a 100644
--- a/apps/client/src/widgets/sidebar/AttributeList.mobile.spec.tsx
+++ b/apps/client/src/widgets/sidebar/AttributeList.mobile.spec.tsx
@@ -24,6 +24,7 @@ vi.mock("../../services/dialog", () => ({ default: { confirm: vi.fn(async () =>
vi.mock("../../services/toast", () => ({ default: { showMessage: vi.fn(), showError: vi.fn() } }));
import FAttribute, { FAttributeRow } from "../../entities/fattribute";
+import { holdAttributes } from "../../services/attribute_clipboard";
import froca from "../../services/froca";
import noteAttributeCache from "../../services/note_attribute_cache";
import options from "../../services/options";
@@ -33,11 +34,16 @@ import AttributeList from "./AttributeList";
describe("AttributeList on a phone", () => {
let container: HTMLElement;
+ let put: ReturnType<typeof vi.fn>;
beforeEach(() => {
vi.clearAllMocks();
options.set("rightPaneCollapsedItems", "[]");
- server.put = (async () => ({})) as unknown as typeof server.put;
+ // What Trilium last copied outlives a render, so each test says for itself whether there is
+ // anything to paste.
+ holdAttributes([]);
+ put = vi.fn(async () => ({}));
+ server.put = put as unknown as typeof server.put;
server.post = (async () => ({ results: [], count: 0 })) as unknown as typeof server.post;
container = document.createElement("div");
document.body.appendChild(container);
@@ -83,6 +89,31 @@ describe("AttributeList on a phone", () => {
expect(container.querySelector(".attribute-add-row")).toBeNull();
});
+ it("offers pasting from the first card's header, which is a phone's only way to it", async () => {
+ // Nothing copied, nothing offered — as the row menu and the selection's bar do.
+ renderPanel(noteWithRuns());
+ expect(iconsIn(header("attributes-owned"))).not.toContain("bx bx-paste");
+
+ // The note that most wants pasting into is the one carrying nothing, and it is exactly the
+ // note where every other way in is gone: no row to hold down, so no selection and no bar,
+ // and the list a press beside the rows would land on has no rows to give it a height. The
+ // header stands whatever the run holds, which is why the way in belongs there.
+ render(null, container);
+ holdAttributes([ { type: "label", name: "author", value: "Elian", isInheritable: false } ]);
+ renderPanel(buildNote({ id: "phone-bare", title: "Bare" }));
+
+ expect(container.querySelectorAll(".attribute-row")).toHaveLength(0);
+ expect(container.querySelector(".attribute-selection-bar")).toBeNull();
+ expect(iconsIn(header("attributes-owned"))).toEqual([ "bx bx-help-circle", "bx bx-paste", "bx bx-plus" ]);
+
+ const paste = header("attributes-owned")?.querySelector<HTMLElement>(".bx-paste");
+ await act(async () => paste?.click());
+
+ const [ url, saved ] = put.mock.calls[0] as [ string, { name: string; value: string }[] ];
+ expect(url).toBe("notes/phone-bare/attributes");
+ expect(saved).toEqual([ { type: "label", name: "author", value: "Elian", isInheritable: false } ]);
+ });
+
it("still picks rows out, by the press held down, and says what can be done with them", () => {
vi.useFakeTimers();
renderPanel(noteWithRuns());
diff --git a/apps/client/src/widgets/sidebar/AttributeList.tsx b/apps/client/src/widgets/sidebar/AttributeList.tsx
index ee669d3bd4..b09f8b4905 100644
--- a/apps/client/src/widgets/sidebar/AttributeList.tsx
+++ b/apps/client/src/widgets/sidebar/AttributeList.tsx
@@ -705,6 +705,10 @@ export default function AttributeList() {
});
}
+ // What Trilium last copied, which is what there is to paste (see the clipboard service). Read
+ // here rather than at each use so that one render offers the same thing everywhere in itself.
+ const heldAttributes = getHeldAttributes();
+
// At the foot of the runs, the rows it acts on being picked out anywhere among them. It holds
// there while they are scrolled (see the stylesheet), so it is the one thing both ways of
// drawing them share: a phone picks rows out by holding one down, a pointer by the checkbox or
@@ -713,9 +717,9 @@ export default function AttributeList() {
<AttributeSelectionBar
count={selection.size}
canDelete={selectedAttributes().every((candidate) => owned.current.includes(candidate))}
- canPaste={getHeldAttributes().length > 0}
+ canPaste={heldAttributes.length > 0}
onCopy={() => void copyPickedAttributes(selectedAttributes())}
- onPaste={() => void applyPaste(getHeldAttributes())}
+ onPaste={() => void applyPaste(heldAttributes)}
onDelete={() => void deleteSelection(selectedAttributes())}
onClear={clearSelection}
/>
@@ -753,6 +757,25 @@ export default function AttributeList() {
// run's.
<>
<HelpButton helpPage={ATTRIBUTE_HELP_PAGE} />
+
+ {/* The only way to paste a phone has. A pointer has three — the key,
+ a right press on a row, a right press beside them — and all three
+ are a pointer's: there is no paste key to press, a row that is held
+ down is being picked out instead, and the list a press beside the
+ rows would land on is nothing at all on the note that most wants
+ pasting into, having no rows to give it a height. The header is the
+ one part of a run that stands whatever the run holds. */}
+ {heldAttributes.length > 0 && (
+ <ActionButton
+ icon="bx bx-paste"
+ text={t("attribute_list_panel.paste", { count: heldAttributes.length })}
+ onClick={(e) => {
+ e.stopPropagation();
+ void applyPaste(heldAttributes);
+ }}
+ />
+ )}
+
<AddAttributeButton
text={t("attribute_editor.add_a_new_attribute")}
attrTypes={ALL_ATTRIBUTE_KINDS}