mirror of
https://github.com/zadam/trilium.git
synced 2025-12-22 07:14:24 +01:00
refactor(search): simplify null check and use join for text concatenation
根据代码审查建议优化代码:
- 移除多余的 `elements &&` 检查,因为 Array.isArray() 本身可处理 null/undefined
- 使用 `join(" ")` 替代 `toString()` 以确保文本元素用空格分隔,更适合全文搜索
- 移除显式类型声明,让 TypeScript 自动推断
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
ecb972c71c
commit
ee6f988c35
@ -315,15 +315,15 @@ class NoteContentFulltextExp extends Expression {
|
||||
[key: string]: any; // Other properties that may exist
|
||||
}
|
||||
|
||||
let canvasContent = JSON.parse(content);
|
||||
const elements: Element[] = canvasContent.elements;
|
||||
const canvasContent = JSON.parse(content);
|
||||
const elements = canvasContent.elements;
|
||||
|
||||
if (elements && Array.isArray(elements)) {
|
||||
if (Array.isArray(elements)) {
|
||||
const texts = elements
|
||||
.filter((element: Element) => element.type === "text" && element.text) // Filter for 'text' type elements with a 'text' property
|
||||
.map((element: Element) => element.text!); // Use `!` to assert `text` is defined after filtering
|
||||
|
||||
content = normalize(texts.toString());
|
||||
content = normalize(texts.join(" "));
|
||||
} else {
|
||||
content = "";
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user