From fd7f3ef2ff48c19795ba49538ddc394b8cf62a40 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 3 Feb 2025 00:49:45 +0200 Subject: [PATCH 1/3] Merge pull request #1101 from TriliumNext/bugfix/mac-paste Remove `mac_init` as it was breaking MacOS --- src/public/app/desktop.ts | 3 --- src/public/app/services/mac_init.ts | 26 -------------------------- src/public/app/setup.ts | 3 --- 3 files changed, 32 deletions(-) delete mode 100644 src/public/app/services/mac_init.ts diff --git a/src/public/app/desktop.ts b/src/public/app/desktop.ts index e6eca440d..d8fad16ef 100644 --- a/src/public/app/desktop.ts +++ b/src/public/app/desktop.ts @@ -4,7 +4,6 @@ import noteTooltipService from "./services/note_tooltip.js"; import bundleService from "./services/bundle.js"; import toastService from "./services/toast.js"; import noteAutocompleteService from "./services/note_autocomplete.js"; -import macInit from "./services/mac_init.js"; import electronContextMenu from "./menus/electron_context_menu.js"; import glob from "./services/glob.js"; import { t } from "./services/i18n.js"; @@ -35,8 +34,6 @@ if (utils.isElectron()) { initOnElectron(); } -macInit.init(); - noteTooltipService.setupGlobalTooltip(); noteAutocompleteService.init(); diff --git a/src/public/app/services/mac_init.ts b/src/public/app/services/mac_init.ts deleted file mode 100644 index c864b3cad..000000000 --- a/src/public/app/services/mac_init.ts +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Mac specific initialization - */ -import utils from "./utils.js"; -import shortcutService from "./shortcuts.js"; - -function init() { - if (utils.isElectron() && utils.isMac()) { - shortcutService.bindGlobalShortcut("meta+c", () => exec("copy")); - shortcutService.bindGlobalShortcut("meta+v", () => exec("paste")); - shortcutService.bindGlobalShortcut("meta+x", () => exec("cut")); - shortcutService.bindGlobalShortcut("meta+a", () => exec("selectAll")); - shortcutService.bindGlobalShortcut("meta+z", () => exec("undo")); - shortcutService.bindGlobalShortcut("meta+y", () => exec("redo")); - } -} - -function exec(cmd: string) { - document.execCommand(cmd); - - return false; -} - -export default { - init -}; diff --git a/src/public/app/setup.ts b/src/public/app/setup.ts index ec389c793..1970c110a 100644 --- a/src/public/app/setup.ts +++ b/src/public/app/setup.ts @@ -1,9 +1,6 @@ import utils from "./services/utils.js"; -import macInit from "./services/mac_init.js"; import ko from "knockout"; -macInit.init(); - // TriliumNextTODO: properly make use of below types // type SetupModelSetupType = "new-document" | "sync-from-desktop" | "sync-from-server" | ""; // type SetupModelStep = "sync-in-progress" | "setup-type" | "new-document-in-progress" | "sync-from-desktop"; From 438f28b5b097f74f3c1d2374a260ac6fd48a4879 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 3 Feb 2025 09:48:06 +0200 Subject: [PATCH 2/3] chore(release): prepare for 0.91.6 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index da8a3c313..ef7966f30 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "trilium", - "version": "0.91.5", + "version": "0.91.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "trilium", - "version": "0.91.5", + "version": "0.91.6", "license": "AGPL-3.0-only", "dependencies": { "@braintree/sanitize-url": "7.1.1", diff --git a/package.json b/package.json index c84735495..7c4a41e3e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "trilium", "productName": "TriliumNext Notes", "description": "Build your personal knowledge base with TriliumNext Notes", - "version": "0.91.5", + "version": "0.91.6", "license": "AGPL-3.0-only", "main": "./dist/electron-main.js", "author": { From 79e830b6ea22e51196bdca4c021f30ecfad92723 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 3 Feb 2025 18:59:56 +0200 Subject: [PATCH 3/3] fix(search): empty mindmap note breaking search (closes #1107) --- .../expressions/note_content_fulltext.spec.ts | 13 +++ .../expressions/note_content_fulltext.ts | 106 ++++++++++-------- 2 files changed, 73 insertions(+), 46 deletions(-) create mode 100644 src/services/search/expressions/note_content_fulltext.spec.ts diff --git a/src/services/search/expressions/note_content_fulltext.spec.ts b/src/services/search/expressions/note_content_fulltext.spec.ts new file mode 100644 index 000000000..9ef4a7d78 --- /dev/null +++ b/src/services/search/expressions/note_content_fulltext.spec.ts @@ -0,0 +1,13 @@ +import { describe, it, expect } from "vitest"; +import { processMindmapContent } from "./note_content_fulltext.js"; + +describe("processMindmapContent", () => { + it("supports empty JSON", () => { + expect(processMindmapContent("{}")).toEqual(""); + }); + + it("supports blank text / invalid JSON", () => { + expect(processMindmapContent("")).toEqual(""); + expect(processMindmapContent(`{ "node": " }`)).toEqual(""); + }); +}); diff --git a/src/services/search/expressions/note_content_fulltext.ts b/src/services/search/expressions/note_content_fulltext.ts index 083fd3d0e..b0a97da76 100644 --- a/src/services/search/expressions/note_content_fulltext.ts +++ b/src/services/search/expressions/note_content_fulltext.ts @@ -131,52 +131,7 @@ class NoteContentFulltextExp extends Expression { content = content.replace(/ /g, " "); } else if (type === "mindMap" && mime === "application/json") { - let mindMapcontent = JSON.parse(content); - - // Define interfaces for the JSON structure - interface MindmapNode { - id: string; - topic: string; - children: MindmapNode[]; // Recursive structure - direction?: number; - expanded?: boolean; - } - - interface MindmapData { - nodedata: MindmapNode; - arrows: any[]; // If you know the structure, replace `any` with the correct type - summaries: any[]; - direction: number; - theme: { - name: string; - type: string; - palette: string[]; - cssvar: Record; // Object with string keys and string values - }; - } - - // Recursive function to collect all topics - function collectTopics(node: MindmapNode): string[] { - // Collect the current node's topic - let topics = [node.topic]; - - // If the node has children, collect topics recursively - if (node.children && node.children.length > 0) { - for (const child of node.children) { - topics = topics.concat(collectTopics(child)); - } - } - - return topics; - } - - // Start extracting from the root node - const topicsArray = collectTopics(mindMapcontent.nodedata); - - // Combine topics into a single string - const topicsString = topicsArray.join(", "); - - content = normalize(topicsString.toString()); + content = processMindmapContent(content); } else if (type === "canvas" && mime === "application/json") { interface Element { type: string; @@ -215,4 +170,63 @@ class NoteContentFulltextExp extends Expression { } } +export function processMindmapContent(content: string) { + let mindMapcontent; + + try { + mindMapcontent = JSON.parse(content); + } catch (e) { + return ""; + } + + // Define interfaces for the JSON structure + interface MindmapNode { + id: string; + topic: string; + children: MindmapNode[]; // Recursive structure + direction?: number; + expanded?: boolean; + } + + interface MindmapData { + nodedata: MindmapNode; + arrows: any[]; // If you know the structure, replace `any` with the correct type + summaries: any[]; + direction: number; + theme: { + name: string; + type: string; + palette: string[]; + cssvar: Record; // Object with string keys and string values + }; + } + + // Recursive function to collect all topics + function collectTopics(node?: MindmapNode): string[] { + if (!node) { + return []; + } + + // Collect the current node's topic + let topics = [node.topic]; + + // If the node has children, collect topics recursively + if (node.children && node.children.length > 0) { + for (const child of node.children) { + topics = topics.concat(collectTopics(child)); + } + } + + return topics; + } + + // Start extracting from the root node + const topicsArray = collectTopics(mindMapcontent.nodedata); + + // Combine topics into a single string + const topicsString = topicsArray.join(", "); + + return normalize(topicsString.toString()); +} + export default NoteContentFulltextExp;