mirror of
https://github.com/EthanMarti/infio-copilot.git
synced 2026-05-08 08:00:10 +00:00
fix unit test
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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>
|
||||
)
|
||||
}
|
||||
@@ -48,6 +48,7 @@ export default function MarkdownEditFileBlock({
|
||||
}
|
||||
setApplying(true)
|
||||
onApply({
|
||||
// @ts-ignore
|
||||
type: mode,
|
||||
filepath: path,
|
||||
content: String(children),
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user