Skip to content

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

fix(mobile): apply exact tag filters on Android and iOS lists

tianma-ifd41d068e0ced
diff --git a/apps/ios/EdgeEver/Data/Database/LocalMirrorRepository.swift b/apps/ios/EdgeEver/Data/Database/LocalMirrorRepository.swift
index 2613cdd5..4e851263 100644
--- a/apps/ios/EdgeEver/Data/Database/LocalMirrorRepository.swift
+++ b/apps/ios/EdgeEver/Data/Database/LocalMirrorRepository.swift
@@ -113,12 +113,6 @@ final class LocalMirrorRepository: @unchecked Sendable {
let pattern = "%\(q)%"
arguments.append(contentsOf: [pattern, pattern, pattern])
}
- if let tag = params.tag?.trimmingCharacters(in: .whitespacesAndNewlines), !tag.isEmpty {
- conditions.append(
- "EXISTS (SELECT 1 FROM json_each(mobile_memos.data_json, '$.tags') AS memo_tag WHERE LOWER(CAST(memo_tag.value AS TEXT)) = LOWER(?))"
- )
- arguments.append(tag)
- }
switch params.filter {
case .all: break
case .tagged: conditions.append("tags_text <> ''")
@@ -138,9 +132,39 @@ final class LocalMirrorRepository: @unchecked Sendable {
}
let whereSQL = conditions.joined(separator: " AND ")
- let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM mobile_memos WHERE \(whereSQL)", arguments: StatementArguments(arguments)) ?? 0
+ let tag = params.tag?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
let limit = params.limit
let offset = max(0, params.offset)
+
+ let decodeRows = { (rows: [Row]) -> [MemoSummary] in
+ var memos: [MemoSummary] = []
+ memos.reserveCapacity(rows.count)
+ for row in rows {
+ let raw = row["data_json"] as String
+ guard let detail = try? EdgeEverJSON.decoder.decode(MemoDetail.self, from: Data(raw.utf8)) else {
+ #if DEBUG
+ print("LocalMirrorRepository.listMemos: skipped undecodable memo json length=\(raw.count)")
+ #endif
+ continue
+ }
+ memos.append(detail.asSummary())
+ }
+ return memos
+ }
+
+ if !tag.isEmpty {
+ let rows = try Row.fetchAll(
+ db,
+ sql: "SELECT data_json FROM mobile_memos WHERE \(whereSQL) ORDER BY \(orderBy)",
+ arguments: StatementArguments(arguments)
+ )
+ let memos = decodeRows(rows).filter { MobileUI.memoHasExactTag(tags: $0.tags, tag: tag) }
+ let page = Array(memos.dropFirst(offset).prefix(limit))
+ let next = offset + page.count
+ return LocalMemoListResult(memos: page, totalCount: memos.count, nextOffset: next < memos.count ? next : nil)
+ }
+
+ let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM mobile_memos WHERE \(whereSQL)", arguments: StatementArguments(arguments)) ?? 0
var listArgs = arguments
listArgs.append(limit)
listArgs.append(offset)
@@ -150,18 +174,7 @@ final class LocalMirrorRepository: @unchecked Sendable {
arguments: StatementArguments(listArgs)
)
// Skip corrupt rows instead of failing the entire list (one bad data_json must not blank the feed).
- var memos: [MemoSummary] = []
- memos.reserveCapacity(rows.count)
- for row in rows {
- let raw = row["data_json"] as String
- guard let detail = try? EdgeEverJSON.decoder.decode(MemoDetail.self, from: Data(raw.utf8)) else {
- #if DEBUG
- print("LocalMirrorRepository.listMemos: skipped undecodable memo json length=\(raw.count)")
- #endif
- continue
- }
- memos.append(detail.asSummary())
- }
+ let memos = decodeRows(rows)
let next = offset + rows.count
return LocalMemoListResult(memos: memos, totalCount: count, nextOffset: next < count ? next : nil)
}
diff --git a/apps/ios/EdgeEver/DesignSystem/MobileUI.swift b/apps/ios/EdgeEver/DesignSystem/MobileUI.swift
index cf5c4c5d..57fa32c8 100644
--- a/apps/ios/EdgeEver/DesignSystem/MobileUI.swift
+++ b/apps/ios/EdgeEver/DesignSystem/MobileUI.swift
@@ -83,6 +83,14 @@ enum MobileUI {
guard current.count < maxSelections else { return current }
return current + [tag]
}
+
+ static func memoHasExactTag(tags: [String], tag: String) -> Bool {
+ let normalized = tag.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
+ guard !normalized.isEmpty else { return true }
+ return tags.contains {
+ $0.trimmingCharacters(in: .whitespacesAndNewlines).lowercased() == normalized
+ }
+ }
}
struct NotebookTreeItem: Identifiable, Equatable {
diff --git a/apps/ios/Tests/EdgeEverTests/MobileUIParityTests.swift b/apps/ios/Tests/EdgeEverTests/MobileUIParityTests.swift
index d638969f..6c09a60b 100644
--- a/apps/ios/Tests/EdgeEverTests/MobileUIParityTests.swift
+++ b/apps/ios/Tests/EdgeEverTests/MobileUIParityTests.swift
@@ -57,6 +57,14 @@ final class MobileUIParityTests: XCTestCase {
)
}
+ func testExactTagMatchIgnoresCaseAndOverlappingNames() {
+ XCTAssertTrue(MobileUI.memoHasExactTag(tags: ["Project Alpha", "Work"], tag: "project alpha"))
+ XCTAssertTrue(MobileUI.memoHasExactTag(tags: ["Project Alpha", "Work"], tag: " project alpha "))
+ XCTAssertFalse(MobileUI.memoHasExactTag(tags: ["Project Alpha", "Work"], tag: "project"))
+ XCTAssertFalse(MobileUI.memoHasExactTag(tags: ["Homework"], tag: "work"))
+ XCTAssertFalse(MobileUI.memoHasExactTag(tags: ["demo-extra"], tag: "demo"))
+ }
+
func testMemoListTimestampMatchesSortMode() {
let memo = MemoSummary(
id: "memo",
diff --git a/apps/mobile/src/lib/local-mirror.ts b/apps/mobile/src/lib/local-mirror.ts
index d4c52bb5..bbd5a731 100644
--- a/apps/mobile/src/lib/local-mirror.ts
+++ b/apps/mobile/src/lib/local-mirror.ts
@@ -9,7 +9,7 @@ import {
type TagSummary,
} from "@edgeever/shared";
import * as SQLite from "expo-sqlite";
-import { summarizeMobileTags } from "./mobile-tags";
+import { filterLocalMemosByExactTag, summarizeMobileTags } from "./mobile-tags";
const DATABASE_NAME = "edgeever-mobile.db";
const BOOTSTRAP_PAGE_SIZE = 200;
@@ -117,12 +117,6 @@ export const listLocalMemos = async (scope: string, params: LocalMemoListParams)
const q = `%${params.q.trim()}%`;
binds.push(q, q, q);
}
- if (params.tag?.trim()) {
- conditions.push(
- "EXISTS (SELECT 1 FROM json_each(mobile_memos.data_json, '$.tags') AS memo_tag WHERE LOWER(CAST(memo_tag.value AS TEXT)) = LOWER(?))"
- );
- binds.push(params.tag.trim());
- }
if (params.filter === "tagged") {
conditions.push("tags_text <> ''");
} else if (params.filter === "untagged") {
@@ -138,14 +132,40 @@ export const listLocalMemos = async (scope: string, params: LocalMemoListParams)
: params.sort === "title-asc"
? "is_pinned DESC, title COLLATE NOCASE ASC, updated_at DESC, id DESC"
: "is_pinned DESC, updated_at DESC, id DESC";
+ const tag = params.tag?.trim() ?? "";
+ const limit = params.limit ?? 50;
+ const offset = Math.max(0, params.offset ?? 0);
+ const whereSql = conditions.join(" AND ");
+
+ if (tag) {
+ const rows = await db.getAllAsync<StoredMemoRow>(
+ `SELECT data_json FROM mobile_memos WHERE ${whereSql} ORDER BY ${orderBy}`,
+ ...binds
+ );
+ const memos = filterLocalMemosByExactTag(
+ rows.flatMap((row) => {
+ try {
+ return [toMemoSummary(JSON.parse(row.data_json) as MemoDetail)];
+ } catch {
+ return [];
+ }
+ }),
+ tag
+ );
+ const page = memos.slice(offset, offset + limit);
+ return {
+ memos: page,
+ totalCount: memos.length,
+ nextCursor: offset + page.length < memos.length ? String(offset + page.length) : null,
+ };
+ }
+
const countRow = await db.getFirstAsync<{ count: number }>(
- `SELECT COUNT(*) AS count FROM mobile_memos WHERE ${conditions.join(" AND ")}`,
+ `SELECT COUNT(*) AS count FROM mobile_memos WHERE ${whereSql}`,
...binds
);
- const limit = params.limit ?? 50;
- const offset = Math.max(0, params.offset ?? 0);
const rows = await db.getAllAsync<StoredMemoRow>(
- `SELECT data_json FROM mobile_memos WHERE ${conditions.join(" AND ")} ORDER BY ${orderBy} LIMIT ? OFFSET ?`,
+ `SELECT data_json FROM mobile_memos WHERE ${whereSql} ORDER BY ${orderBy} LIMIT ? OFFSET ?`,
...binds,
limit,
offset
diff --git a/apps/mobile/src/lib/mobile-tags.test.ts b/apps/mobile/src/lib/mobile-tags.test.ts
index abed5056..c67a848c 100644
--- a/apps/mobile/src/lib/mobile-tags.test.ts
+++ b/apps/mobile/src/lib/mobile-tags.test.ts
@@ -1,6 +1,6 @@
import { expect, test } from "bun:test";
import type { MemoDetail } from "@edgeever/shared";
-import { summarizeMobileTags } from "./mobile-tags";
+import { filterLocalMemosByExactTag, memoHasExactTag, summarizeMobileTags } from "./mobile-tags";
const memo = (id: string, tags: string[], updatedAt: string, isDeleted = false) => ({
id,
@@ -9,6 +9,25 @@ const memo = (id: string, tags: string[], updatedAt: string, isDeleted = false)
isDeleted,
} as MemoDetail);
+test("matches one exact tag without depending on case or overlapping names", () => {
+ expect(memoHasExactTag(["Project Alpha", "Work"], "project alpha")).toBe(true);
+ expect(memoHasExactTag(["Project Alpha", "Work"], " project alpha ")).toBe(true);
+ expect(memoHasExactTag(["Project Alpha", "Work"], "project")).toBe(false);
+ expect(memoHasExactTag(["Homework"], "work")).toBe(false);
+ expect(memoHasExactTag(["demo-extra"], "demo")).toBe(false);
+});
+
+test("filters a memo list to one exact tag before pagination", () => {
+ const memos = [
+ { id: "exact", tags: ["Project Alpha", "Work"] },
+ { id: "substring", tags: ["Project"] },
+ { id: "untagged", tags: [] },
+ ];
+
+ expect(filterLocalMemosByExactTag(memos, "project alpha").map((memo) => memo.id)).toEqual(["exact"]);
+ expect(filterLocalMemosByExactTag(memos, "").map((memo) => memo.id)).toEqual(["exact", "substring", "untagged"]);
+});
+
test("summarizes active memo tags for the offline picker", () => {
expect(summarizeMobileTags([
memo("1", ["work", "shared", "work"], "2026-08-13T00:00:00.000Z"),
diff --git a/apps/mobile/src/lib/mobile-tags.ts b/apps/mobile/src/lib/mobile-tags.ts
index 18801664..f9c94b5c 100644
--- a/apps/mobile/src/lib/mobile-tags.ts
+++ b/apps/mobile/src/lib/mobile-tags.ts
@@ -1,5 +1,20 @@
import type { MemoDetail, TagSummary } from "@edgeever/shared";
+export const memoHasExactTag = (tags: readonly string[] | null | undefined, tag: string) => {
+ const normalized = tag.trim().toLocaleLowerCase();
+ if (!normalized) return true;
+ return (tags ?? []).some((value) => value.trim().toLocaleLowerCase() === normalized);
+};
+
+export const filterLocalMemosByExactTag = <T extends { tags: string[] }>(
+ memos: T[],
+ tag?: string | null
+): T[] => {
+ const normalized = tag?.trim() ?? "";
+ if (!normalized) return memos;
+ return memos.filter((memo) => memoHasExactTag(memo.tags, normalized));
+};
+
export const summarizeMobileTags = (memos: MemoDetail[]): TagSummary[] => {
const tags = new Map<string, { memoCount: number; updatedAt: string | null }>();
diff --git a/apps/mobile/src/screens/workspace-memo-cache.ts b/apps/mobile/src/screens/workspace-memo-cache.ts
index a813d3e1..729932fb 100644
--- a/apps/mobile/src/screens/workspace-memo-cache.ts
+++ b/apps/mobile/src/screens/workspace-memo-cache.ts
@@ -1,6 +1,7 @@
import { type InfiniteData, type QueryClient } from "@tanstack/react-query";
import type { MemoDetail, MemoSummary, Notebook, TiptapDoc } from "@edgeever/shared";
import { listLocalMemos } from "../lib/local-mirror";
+import { memoHasExactTag } from "../lib/mobile-tags";
import { markdownToLocalText, sortMemoSummaries } from "./workspace-utils";
const ALL_NOTES_ID = "all";
@@ -44,7 +45,7 @@ export const memoMatchesListQuery = (memo: MemoSummary, queryKey: readonly unkno
const notebookId = queryKey[3];
const filter = queryKey[4];
const notebookIds = Array.isArray(queryKey[6]) ? queryKey[6] : [];
- const tag = typeof queryKey[7] === "string" ? queryKey[7].trim().toLocaleLowerCase() : "";
+ const tag = typeof queryKey[7] === "string" ? queryKey[7] : "";
if ((view === "trash") !== memo.isDeleted) {
return false;
@@ -52,7 +53,7 @@ export const memoMatchesListQuery = (memo: MemoSummary, queryKey: readonly unkno
if (notebookId !== ALL_NOTES_ID && !notebookIds.includes(memo.notebookId)) {
return false;
}
- if (tag && !memo.tags.some((memoTag) => memoTag.toLocaleLowerCase() === tag)) {
+ if (tag && !memoHasExactTag(memo.tags, tag)) {
return false;
}
if (filter === "tagged" && memo.tags.length === 0) {
diff --git a/tests/mobile-app-scope.test.ts b/tests/mobile-app-scope.test.ts
index 6f1efa40..f41babad 100644
--- a/tests/mobile-app-scope.test.ts
+++ b/tests/mobile-app-scope.test.ts
@@ -25,6 +25,18 @@ const iosWorkspaceViewSource = readFileSync(
new URL("../apps/ios/EdgeEver/Features/Workspace/WorkspaceView.swift", import.meta.url),
"utf8"
);
+const mobileTagsSource = readFileSync(
+ new URL("../apps/mobile/src/lib/mobile-tags.ts", import.meta.url),
+ "utf8"
+);
+const mobileLocalMirrorSource = readFileSync(
+ new URL("../apps/mobile/src/lib/local-mirror.ts", import.meta.url),
+ "utf8"
+);
+const iosLocalMirrorSource = readFileSync(
+ new URL("../apps/ios/EdgeEver/Data/Database/LocalMirrorRepository.swift", import.meta.url),
+ "utf8"
+);
const mobileDomSource = readFileSync(
new URL("../apps/mobile/src/lib/mobile-dom.ts", import.meta.url),
"utf8"
@@ -112,6 +124,15 @@ describe("mobile app scope", () => {
expect(iosWorkspaceViewSource).not.toContain('env.preferences.t("无标签", en: "Untagged")');
});
+ test("applies exact tag matching in the local memo list instead of json_each on the full note blob", () => {
+ expect(workspaceSource).toContain("tag: memoView === \"notebook\" ? selectedTag ?? undefined : undefined");
+ expect(mobileTagsSource).toContain("filterLocalMemosByExactTag");
+ expect(mobileLocalMirrorSource).toContain("filterLocalMemosByExactTag");
+ expect(mobileLocalMirrorSource).not.toContain("json_each(mobile_memos.data_json");
+ expect(iosLocalMirrorSource).toContain("MobileUI.memoHasExactTag");
+ expect(iosLocalMirrorSource).not.toContain("json_each(mobile_memos.data_json");
+ });
+
test("keeps Android memo list motion and spring feedback", () => {
expect(notesViewSource).toContain("FadeInDown.duration(260).springify().damping(18)");
expect(notesViewSource).toContain("FadeOutUp.duration(220)");