refactor(editor): migrate to Milkdown with LaTeX support and clean up legacy code

- Removed old contenteditable-based MarkdownEditor component
- Integrated Milkdown Crepe with LaTeX (KaTeX) rendering support
- Simplified inline suggestion plugin using ProseMirror decorations
- Removed debug logging and unused components (HelloWorld, plan files)
- Increased debounce from 150ms to 500ms for better performance
- Fixed SSE JSON serialization in backend main.py
This commit is contained in:
“ydy0615”
2026-02-12 18:52:16 +08:00
parent 2432e78fe1
commit 16e76e1e90
14 changed files with 487 additions and 2300 deletions

View File

@@ -1,52 +1,30 @@
import { DEBUG, API_URL } from './config.js'
export async function fetchSuggestion(prefix, suffix, apiUrl = 'http://localhost:8000/v1/completions') {
const res = await fetch(apiUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prefix, suffix, languageId: 'markdown' }),
})
export async function fetchSuggestion(prefix, suffix, apiUrl = API_URL) {
if (DEBUG) console.log('[Debug] fetchSuggestion called with prefix length:', prefix.length, 'suffix length:', suffix.length)
try {
const res = await fetch(apiUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prefix, suffix, languageId: 'markdown' }),
})
if (!res.ok) {
throw new Error(`HTTP ${res.status}`)
}
if (DEBUG) console.log('[Debug] fetchSuggestion response status:', res.status)
if (!res.ok) {
const errorText = await res.text()
throw new Error(`HTTP ${res.status}: ${errorText}`)
}
const reader = res.body?.getReader()
if (!reader) throw new Error('No reader available')
const reader = res.body?.getReader()
if (!reader) {
if (DEBUG) console.log('[Debug] No reader available')
throw new Error('No reader available')
}
let text = ''
while (true) {
const { done, value } = await reader.read()
if (done) break
const chunk = new TextDecoder().decode(value)
if (DEBUG) console.log('[Debug] Received chunk:', chunk.substring(0, 100))
const lines = chunk.split('\n').filter(l => l.startsWith('data: '))
for (const line of lines) {
try {
const data = JSON.parse(line.slice(6))
if (data.content) {
text += data.content
if (DEBUG) console.log('[Debug] Added content:', data.content)
}
if (data.done || data.error) break
} catch (e) {
if (DEBUG) console.warn('[Debug] JSON parse error:', e)
}
}
}
if (DEBUG) console.log('[Debug] Final suggestion text:', text.substring(0, 100))
return text
} catch (e) {
if (DEBUG) console.error('[Debug] fetchSuggestion error:', e)
throw e
let text = ''
while (true) {
const { done, value } = await reader.read()
if (done) break
const chunk = new TextDecoder().decode(value)
const lines = chunk.split('\n').filter(l => l.startsWith('data: '))
for (const line of lines) {
try {
const data = JSON.parse(line.slice(6))
if (data.content) text += data.content
if (data.done || data.error) break
} catch (e) {}
}
}
return text
}