Skip to content

Build your personal knowledge base with Trilium Notes

fix(collections/table): let Ctrl and Shift clicks open a title's note

Elian Dorane510e2e64e3a
diff --git a/apps/client/src/widgets/collections/table/columns.spec.ts b/apps/client/src/widgets/collections/table/columns.spec.ts
index 2da24262b6..8f71d43973 100644
--- a/apps/client/src/widgets/collections/table/columns.spec.ts
+++ b/apps/client/src/widgets/collections/table/columns.spec.ts
@@ -791,4 +791,25 @@ describe("title column", () => {
expect(goToLinkExt).toHaveBeenCalledWith(expect.any(MouseEvent), "#root/abc123");
expect(cellClick).not.toHaveBeenCalled();
});
+
+ // Tabulator opens the editor when the cell takes focus, which a press gives it before the click
+ // arrives, so a press meant for the link must not focus the cell.
+ it("keeps a Ctrl, Shift or middle press on the title from focusing the cell, but not a plain one", () => {
+ const { cellElement, title } = renderTitleCell({ editable: true });
+ const cellMouseDown = vi.fn();
+ cellElement.addEventListener("mousedown", cellMouseDown);
+ const press = (init: MouseEventInit) => {
+ const event = new MouseEvent("mousedown", { bubbles: true, cancelable: true, ...init });
+ title.dispatchEvent(event);
+ return event.defaultPrevented;
+ };
+
+ expect(press({ ctrlKey: true })).toBe(true);
+ expect(press({ shiftKey: true })).toBe(true);
+ expect(press({ button: 1 })).toBe(true);
+ expect(cellMouseDown).not.toHaveBeenCalled();
+
+ expect(press({})).toBe(false);
+ expect(cellMouseDown).toHaveBeenCalledTimes(1);
+ });
});
diff --git a/apps/client/src/widgets/collections/table/columns.tsx b/apps/client/src/widgets/collections/table/columns.tsx
index eefc993585..8344b08340 100644
--- a/apps/client/src/widgets/collections/table/columns.tsx
+++ b/apps/client/src/widgets/collections/table/columns.tsx
@@ -384,6 +384,13 @@ function TitleFormatter({ cell }: FormatterOpts) {
<span
className={`reference-link ${colorClass}`}
data-href={href}
+ onMouseDown={(e) => {
+ // The press would focus the cell, and Tabulator opens the editor on focus.
+ if (isCtrlKey(e) || e.shiftKey || e.button === 1) {
+ e.preventDefault();
+ e.stopPropagation();
+ }
+ }}
onClick={(e) => {
if (isCtrlKey(e) || e.shiftKey) {
e.stopPropagation();