From 5118b3e3a71c0cd4bb25c73a566a8df1b4a937ea Mon Sep 17 00:00:00 2001 From: duanfuxiang Date: Tue, 8 Apr 2025 14:05:51 +0800 Subject: [PATCH] fix new note name with markdown title like '####' --- src/components/chat-view/MarkdownWithIcon.tsx | 7 ++++++- src/utils/prompt-generator.ts | 2 -- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/chat-view/MarkdownWithIcon.tsx b/src/components/chat-view/MarkdownWithIcon.tsx index 4da12a0..eb43bbc 100644 --- a/src/components/chat-view/MarkdownWithIcon.tsx +++ b/src/components/chat-view/MarkdownWithIcon.tsx @@ -45,8 +45,13 @@ function CreateNewFileButton({ message }: { message: string }) { const app = useApp() const [created, setCreated] = useState(false) + const cleanMarkdownTitle = (text: string): string => { + // 移除所有 # 开头的标题标记 + return text.replace(/^#+\s*/g, ''); + } + const handleCreate = async () => { - const firstLine = message.trimStart().split('\n')[0].trim().replace(/[\\\/:]/g, ''); + const firstLine = cleanMarkdownTitle(message.trimStart().split('\n')[0].trim()).replace(/[\\/:]/g, ''); const filename = firstLine.slice(0, 200) + (firstLine.length > 200 ? '...' : '') || 'untitled'; await app.vault.create(`/${filename}.md`, message) await app.workspace.openLinkText(filename, 'split', true) diff --git a/src/utils/prompt-generator.ts b/src/utils/prompt-generator.ts index 742a356..959c760 100644 --- a/src/utils/prompt-generator.ts +++ b/src/utils/prompt-generator.ts @@ -172,8 +172,6 @@ export class PromptGenerator { let filesSearchMethod = this.settings.filesSearchMethod if (filesSearchMethod === 'auto' && this.settings.embeddingModelId && this.settings.embeddingModelId !== '') { filesSearchMethod = 'semantic' - } else { - filesSearchMethod = 'regex' } const userLanguage = getFullLanguageName(getLanguage())