fix unit test

This commit is contained in:
duanfuxiang
2025-04-08 14:53:05 +08:00
parent 5118b3e3a7
commit 520fe80d11
16 changed files with 79 additions and 462 deletions

View File

@@ -578,6 +578,7 @@ const Chat = forwardRef<ChatRef, ChatProps>((props, ref) => {
}
}
} else if (toolArgs.type === 'regex_search_files') {
// @ts-expect-error Obsidian API type mismatch
const baseVaultPath = app.vault.adapter.getBasePath()
const ripgrepPath = settings.ripgrepPath
const absolutePath = path.join(baseVaultPath, toolArgs.filepath)

View File

@@ -1,127 +0,0 @@
import { Check, CopyIcon, Loader2 } from 'lucide-react'
import { PropsWithChildren, useMemo, useState } from 'react'
import { useDarkModeContext } from '../../contexts/DarkModeContext'
import { ToolArgs } from "../../types/apply"
import { InfioBlockAction } from '../../utils/parse-infio-block'
import { MemoizedSyntaxHighlighterWrapper } from './SyntaxHighlighterWrapper'
export default function MarkdownActionBlock({
msgId,
onApply,
isApplying,
language,
filename,
startLine,
endLine,
action,
children,
}: PropsWithChildren<{
msgId: string,
onApply: (args: ToolArgs) => void
isApplying: boolean
language?: string
filename?: string
startLine?: number
endLine?: number
action?: InfioBlockAction
}>) {
const [copied, setCopied] = useState(false)
const { isDarkMode } = useDarkModeContext()
const wrapLines = useMemo(() => {
return !language || ['markdown'].includes(language)
}, [language])
const handleCopy = async () => {
try {
await navigator.clipboard.writeText(String(children))
setCopied(true)
setTimeout(() => setCopied(false), 2000)
} catch (err) {
console.error('Failed to copy text: ', err)
}
}
return (
<div className={`infio-chat-code-block ${filename ? 'has-filename' : ''} ${action ? `type-${action}` : ''}`}>
<div className={'infio-chat-code-block-header'}>
{filename && (
<div className={'infio-chat-code-block-header-filename'}>{filename}</div>
)}
<div className={'infio-chat-code-block-header-button'}>
<button
onClick={() => {
handleCopy()
}}
>
{copied ? (
<>
<Check size={10} /> Copied
</>
) : (
<>
<CopyIcon size={10} /> Copy
</>
)}
</button>
{action === InfioBlockAction.Edit && (
<button
onClick={() => {
onApply({
type: 'write_to_file',
msgId,
content: String(children),
filepath: filename,
startLine,
endLine
})
}}
disabled={isApplying}
>
{isApplying ? (
<>
<Loader2 className="spinner" size={14} /> Applying...
</>
) : (
'Apply'
)}
</button>
)}
{action === InfioBlockAction.New && (
<button
onClick={() => {
onApply({
type: 'write_to_file',
msgId,
content: String(children),
filepath: filename,
startLine: 1,
endLine: undefined
})
}}
disabled={isApplying}
>
{isApplying ? (
<>
<Loader2 className="spinner" size={14} /> Inserting...
</>
) : (
'Insert'
)}
</button>
)}
</div>
</div>
<MemoizedSyntaxHighlighterWrapper
isDarkMode={isDarkMode}
language={language}
hasFilename={!!filename}
wrapLines={wrapLines}
>
{String(children)}
</MemoizedSyntaxHighlighterWrapper>
</div>
)
}

View File

@@ -48,6 +48,7 @@ export default function MarkdownEditFileBlock({
}
setApplying(true)
onApply({
// @ts-ignore
type: mode,
filepath: path,
content: String(children),

View File

@@ -16,7 +16,7 @@ export default function DragDropPaste({
useEffect(() => {
return editor.registerCommand(
DRAG_DROP_PASTE, // dispatched in RichTextPlugin
(files) => {
(files: File[]) => {
; (async () => {
const images = files.filter((file) => file.type.startsWith('image/'))
const mentionableImages = await Promise.all(