Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(web): keep bulk-move target from snapping back to the current notebook

tianma-if7a257edfe9db
diff --git a/apps/web/src/components/MemoListPane.test.mjs b/apps/web/src/components/MemoListPane.test.mjs
index 06411c41..796ad1ab 100644
--- a/apps/web/src/components/MemoListPane.test.mjs
+++ b/apps/web/src/components/MemoListPane.test.mjs
@@ -28,3 +28,17 @@ describe("empty memo list creation", () => {
expect(source).not.toContain('onClick={onCreateMemo} disabled={isCreating}');
});
});
+
+describe("desktop bulk move", () => {
+ test("keeps a user-chosen notebook instead of snapping back to the current notebook", () => {
+ const memoListSource = readFileSync(new URL("./MemoListPane.tsx", import.meta.url), "utf8");
+ const workspaceSource = readFileSync(new URL("./WorkspaceApp.tsx", import.meta.url), "utf8");
+
+ expect(memoListSource).toContain("resolveSelectionMoveTargetNotebookId");
+ expect(memoListSource).toContain("disabled={selectedCount === 0 || !moveTargetNotebookId || isMoving || isTrashView || !canMove}");
+ expect(workspaceSource).toContain("resolveSelectionMoveTargetNotebookId");
+ expect(workspaceSource).toContain("canMove={canMoveSelectedMemos}");
+ expect(workspaceSource).not.toContain("setSelectionMoveTargetNotebookId(selectedNotebook.id)");
+ expect(memoListSource).not.toContain("setMoveTargetNotebookId(notebook.id)");
+ });
+});
diff --git a/apps/web/src/components/MemoListPane.tsx b/apps/web/src/components/MemoListPane.tsx
index cfc0a06f..646949f1 100644
--- a/apps/web/src/components/MemoListPane.tsx
+++ b/apps/web/src/components/MemoListPane.tsx
@@ -84,6 +84,7 @@ import {
getMemoFilterOptions,
getMemoSortOptions,
getNotebookMoveOptions,
+ resolveSelectionMoveTargetNotebookId,
readMemoListDensityPreference,
writeMemoListDensityPreference,
} from "@/lib/app-helpers";
@@ -104,6 +105,7 @@ const getSelectionCountLabel = (count: number, t: ReturnType<typeof useTranslati
count > 0 ? t("memoList.selectionCount", { count }) : t("memoList.selectMemo");
export const MemoSelectionActionBar = ({
+ canMove,
deleteTitle,
exportTitle,
isDeleting,
@@ -128,6 +130,7 @@ export const MemoSelectionActionBar = ({
selectedCount,
onMoveTargetChange,
}: {
+ canMove: boolean;
deleteTitle: string;
exportTitle: string;
isDeleting: boolean;
@@ -185,7 +188,7 @@ export const MemoSelectionActionBar = ({
variant="soft"
title={moveTitle}
onClick={onMove}
- disabled={selectedCount === 0 || !moveTargetNotebookId || isMoving || isTrashView}
+ disabled={selectedCount === 0 || !moveTargetNotebookId || isMoving || isTrashView || !canMove}
>
<Folder className="h-4 w-4" />
{t("memoList.move")}
@@ -630,13 +633,14 @@ export const MemoListPane = ({
};
useEffect(() => {
- if (notebook?.id) {
- setMoveTargetNotebookId(notebook.id);
- return;
- }
-
- if (!moveTargetNotebookId && moveNotebookOptions[0]?.id) {
- setMoveTargetNotebookId(moveNotebookOptions[0].id);
+ const nextTargetId = resolveSelectionMoveTargetNotebookId(
+ moveTargetNotebookId,
+ moveNotebookOptions.map((option) => option.id),
+ notebook?.id
+ );
+
+ if (nextTargetId !== moveTargetNotebookId) {
+ setMoveTargetNotebookId(nextTargetId);
}
}, [moveNotebookOptions, moveTargetNotebookId, notebook?.id]);
diff --git a/apps/web/src/components/WorkspaceApp.tsx b/apps/web/src/components/WorkspaceApp.tsx
index 93771635..8ede23e2 100644
--- a/apps/web/src/components/WorkspaceApp.tsx
+++ b/apps/web/src/components/WorkspaceApp.tsx
@@ -77,6 +77,8 @@ import {
getExpandableNotebookIds,
filterNotebookTree,
getNotebookMoveOptions,
+ getMemoIdsNeedingMove,
+ resolveSelectionMoveTargetNotebookId,
} from "@/lib/app-helpers";
import { useBrowserBackLayer } from "@/lib/app-hooks";
import { updateMemoSummaryInLists, type MemoListQueryData } from "@/lib/memo-list-cache";
@@ -2100,13 +2102,14 @@ export const WorkspaceApp = ({
);
useEffect(() => {
- if (selectedNotebook?.id) {
- setSelectionMoveTargetNotebookId(selectedNotebook.id);
- return;
- }
+ const nextTargetId = resolveSelectionMoveTargetNotebookId(
+ selectionMoveTargetNotebookId,
+ selectionMoveNotebookOptions.map((option) => option.id),
+ selectedNotebook?.id
+ );
- if (!selectionMoveTargetNotebookId && selectionMoveNotebookOptions[0]?.id) {
- setSelectionMoveTargetNotebookId(selectionMoveNotebookOptions[0].id);
+ if (nextTargetId !== selectionMoveTargetNotebookId) {
+ setSelectionMoveTargetNotebookId(nextTargetId);
}
}, [selectedNotebook?.id, selectionMoveNotebookOptions, selectionMoveTargetNotebookId]);
@@ -2255,17 +2258,12 @@ export const WorkspaceApp = ({
});
};
- const getMemoIdsNeedingMove = (memoIds: string[], targetNotebookId: string) => {
- const memoNotebookMap = new Map(memos.map((memo) => [memo.id, memo.notebookId]));
- return Array.from(new Set(memoIds.filter(Boolean))).filter((memoId) => memoNotebookMap.get(memoId) !== targetNotebookId);
- };
-
const handleMoveSelectedMemos = (targetNotebookId: string) => {
if (selectedMemoIds.size === 0 || memoView === "trash") {
return;
}
- const memoIds = getMemoIdsNeedingMove(Array.from(selectedMemoIds), targetNotebookId);
+ const memoIds = getMemoIdsNeedingMove(memos, Array.from(selectedMemoIds), targetNotebookId);
if (memoIds.length === 0) {
return;
}
@@ -2281,7 +2279,7 @@ export const WorkspaceApp = ({
return;
}
- const movableMemoIds = getMemoIdsNeedingMove(memoIds, targetNotebookId);
+ const movableMemoIds = getMemoIdsNeedingMove(memos, memoIds, targetNotebookId);
if (movableMemoIds.length === 0) {
return;
}
@@ -2297,7 +2295,7 @@ export const WorkspaceApp = ({
return;
}
- const memoIds = getMemoIdsNeedingMove([memoId], targetNotebookId);
+ const memoIds = getMemoIdsNeedingMove(memos, [memoId], targetNotebookId);
if (memoIds.length === 0) {
return;
}
@@ -2432,6 +2430,12 @@ export const WorkspaceApp = ({
: pinMemosMutation.isPending
? t("workspace.selection.updatingPin")
: selectionPinLabel;
+ const selectedMemosNeedingMove = getMemoIdsNeedingMove(
+ memos,
+ Array.from(selectedMemoIds),
+ selectionMoveTargetNotebookId
+ );
+ const canMoveSelectedMemos = selectedMemosNeedingMove.length > 0;
const selectionMoveTitle =
selectedMemoIds.size === 0
? t("workspace.selection.chooseMemo")
@@ -2441,7 +2445,9 @@ export const WorkspaceApp = ({
? t("workspace.selection.noMovableNotebook")
: moveMemosMutation.isPending
? t("workspace.selection.moving")
- : t("workspace.selection.move");
+ : !canMoveSelectedMemos
+ ? t("workspace.selection.alreadyInNotebook")
+ : t("workspace.selection.move");
const selectionMergeTitle =
selectedMemoIds.size < 2
? t("workspace.selection.needTwoMemos")
@@ -2471,6 +2477,7 @@ export const WorkspaceApp = ({
: t("workspace.selection.delete");
const memoSelectionActionBar = memoSelectionModeActive ? (
<MemoSelectionActionBar
+ canMove={canMoveSelectedMemos}
deleteTitle={selectionDeleteTitle}
exportTitle={selectionExportTitle}
isDeleting={deleteMemosMutation.isPending || deleteMemoMutation.isPending}
diff --git a/apps/web/src/lib/app-helpers.test.mjs b/apps/web/src/lib/app-helpers.test.mjs
index e1a1fff2..aced9cf5 100644
--- a/apps/web/src/lib/app-helpers.test.mjs
+++ b/apps/web/src/lib/app-helpers.test.mjs
@@ -24,6 +24,8 @@ import {
writeDesktopReadingProtectionPreference,
writeEditorOutlineCollapsedPreference,
writeEditorToolbarExpandedPreference,
+ resolveSelectionMoveTargetNotebookId,
+ getMemoIdsNeedingMove,
} from "./app-helpers.ts";
const originalWindow = globalThis.window;
@@ -393,3 +395,27 @@ describe("workspace shortcut preferences", () => {
)).toBe("toggleOutline");
});
});
+
+describe("selection move target", () => {
+ test("keeps a valid user-chosen notebook instead of snapping back to the current notebook", () => {
+ expect(resolveSelectionMoveTargetNotebookId("target-2", ["inbox", "target-2"], "inbox")).toBe("target-2");
+ });
+
+ test("falls back to the current notebook only when the stored target is missing or invalid", () => {
+ expect(resolveSelectionMoveTargetNotebookId("", ["inbox", "archive"], "inbox")).toBe("inbox");
+ expect(resolveSelectionMoveTargetNotebookId("deleted", ["inbox", "archive"], "inbox")).toBe("inbox");
+ expect(resolveSelectionMoveTargetNotebookId("", ["inbox", "archive"], null)).toBe("inbox");
+ });
+
+ test("moves only notes that are not already in the target notebook", () => {
+ const memos = [
+ { id: "memo-1", notebookId: "inbox" },
+ { id: "memo-2", notebookId: "archive" },
+ { id: "memo-3", notebookId: "inbox" },
+ ];
+
+ expect(getMemoIdsNeedingMove(memos, ["memo-1", "memo-2", "memo-3"], "archive")).toEqual(["memo-1", "memo-3"]);
+ expect(getMemoIdsNeedingMove(memos, ["memo-2"], "archive")).toEqual([]);
+ expect(getMemoIdsNeedingMove(memos, ["memo-1"], "")).toEqual([]);
+ });
+});
diff --git a/apps/web/src/lib/app-helpers.ts b/apps/web/src/lib/app-helpers.ts
index 29c4d55a..b8fa7b5e 100644
--- a/apps/web/src/lib/app-helpers.ts
+++ b/apps/web/src/lib/app-helpers.ts
@@ -669,6 +669,35 @@ export const getNotebookMoveOptions = (notebooks: Notebook[]) => {
return options;
};
+export const resolveSelectionMoveTargetNotebookId = (
+ currentTargetId: string,
+ optionIds: string[],
+ selectedNotebookId?: string | null
+) => {
+ if (optionIds.includes(currentTargetId)) {
+ return currentTargetId;
+ }
+
+ if (selectedNotebookId && optionIds.includes(selectedNotebookId)) {
+ return selectedNotebookId;
+ }
+
+ return optionIds[0] ?? "";
+};
+
+export const getMemoIdsNeedingMove = (
+ memos: Array<{ id: string; notebookId: string }>,
+ memoIds: string[],
+ targetNotebookId: string
+) => {
+ if (!targetNotebookId) {
+ return [];
+ }
+
+ const memoNotebookMap = new Map(memos.map((memo) => [memo.id, memo.notebookId]));
+ return Array.from(new Set(memoIds.filter(Boolean))).filter((memoId) => memoNotebookMap.get(memoId) !== targetNotebookId);
+};
+
export const hasMemoDragData = (dataTransfer: DataTransfer) => Array.from(dataTransfer.types).includes(MEMO_DRAG_MIME);
export const hasNotebookDragData = (dataTransfer: DataTransfer) => Array.from(dataTransfer.types).includes(NOTEBOOK_DRAG_MIME);
export const hasEdgeEverDragData = (dataTransfer: DataTransfer) => hasMemoDragData(dataTransfer) || hasNotebookDragData(dataTransfer);
diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.ts
index 3ae73f3e..8d4e47f4 100644
--- a/packages/shared/src/i18n/en-US.ts
+++ b/packages/shared/src/i18n/en-US.ts
@@ -433,6 +433,7 @@ export const enUS = {
noMovableNotebook: "No notebook available",
moving: "Moving",
move: "Move",
+ alreadyInNotebook: "Selected notes are already in this notebook",
needTwoMemos: "Select at least 2 notes",
trashCannotMerge: "Notes in trash cannot be merged",
merging: "Merging",
diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.ts
index 2869ed80..dd87c7f0 100644
--- a/packages/shared/src/i18n/zh-CN.ts
+++ b/packages/shared/src/i18n/zh-CN.ts
@@ -433,6 +433,7 @@ export const zhCN = {
noMovableNotebook: "没有可移动的笔记本",
moving: "正在移动",
move: "移动",
+ alreadyInNotebook: "所选笔记已在该笔记本中",
needTwoMemos: "至少选择 2 条笔记",
trashCannotMerge: "回收站内不可合并",
merging: "正在合并",