feat(ui): enhance theme toggle styling and add Chinese localization
- Redesign theme toggle with improved visual effects including gradient overlays, enhanced shadows, and smoother cubic-bezier transitions - Update toggle dimensions and icon positioning for better visual balance - Add SVG filter effects for sun/moon icons in dark mode - Replace English UI text with Chinese localization in MilkdownEditor - Refactor copilotPlugin by removing unused decoration functions and improving ghost mark text node handling
This commit is contained in:
@@ -3,7 +3,6 @@ import { $prose, $ctx, $markSchema } from '@milkdown/kit/utils'
|
||||
import { parserCtx, serializerCtx } from '@milkdown/kit/core'
|
||||
import { Node as ProseNode, DOMParser, DOMSerializer } from '@milkdown/prose/model'
|
||||
import type { Ctx } from '@milkdown/kit/core'
|
||||
import { Decoration, DecorationSet } from '@milkdown/prose/view'
|
||||
import type { EditorView } from '@milkdown/prose/view'
|
||||
import { getOcrCache, OCR_SIZE_LIMIT, extractTextFromOCR } from '../utils/ocrCache'
|
||||
|
||||
@@ -119,26 +118,6 @@ function clearGhostText(view: EditorView): boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
function buildGhostBlockDecorations(state: any): DecorationSet | null {
|
||||
const pluginState = COPILOT_PLUGIN_KEY.getState(state) as CopilotState | undefined
|
||||
if (!pluginState || !pluginState.suggestion || pluginState.from >= pluginState.to) {
|
||||
return null
|
||||
}
|
||||
|
||||
const from = Math.max(0, Math.min(pluginState.from, state.doc.content.size))
|
||||
const to = Math.max(from, Math.min(pluginState.to, state.doc.content.size))
|
||||
const decorations: Decoration[] = []
|
||||
|
||||
state.doc.nodesBetween(from, to, (node: any, pos: number) => {
|
||||
if (!node.isBlock || node.nodeSize <= 0) return true
|
||||
decorations.push(Decoration.node(pos, pos + node.nodeSize, { class: 'copilot-ghost-block' }))
|
||||
return true
|
||||
})
|
||||
|
||||
if (decorations.length === 0) return null
|
||||
return DecorationSet.create(state.doc, decorations)
|
||||
}
|
||||
|
||||
function getCursorBeforeGhostInsert(tr: any, from: number): number {
|
||||
const mapped = tr.mapping.map(from, -1)
|
||||
return Math.max(0, Math.min(mapped, tr.doc.content.size))
|
||||
@@ -167,9 +146,13 @@ function addGhostMarksToTextNodes(tr: any, from: number, to: number, markType: a
|
||||
tr.doc.nodesBetween(from, to, (node: any, pos: number) => {
|
||||
if (!node.isText || node.nodeSize <= 0) return true
|
||||
|
||||
const $pos = tr.doc.resolve(pos)
|
||||
const start = Math.max(pos, from)
|
||||
const end = Math.min(pos + node.nodeSize, to)
|
||||
if (end <= start) return true
|
||||
|
||||
const $pos = tr.doc.resolve(start)
|
||||
if ($pos.parent.type.allowsMarkType?.(markType)) {
|
||||
tr.addMark(pos, pos + node.nodeSize, markType.create())
|
||||
tr.addMark(start, end, markType.create())
|
||||
}
|
||||
return true
|
||||
})
|
||||
@@ -454,7 +437,6 @@ export const copilotPlugin = $prose((ctx) => new Plugin<CopilotState>({
|
||||
}
|
||||
},
|
||||
props: {
|
||||
decorations: (state) => buildGhostBlockDecorations(state),
|
||||
handleKeyDown: (view, event) => {
|
||||
const hasGhost = hasGhostText(view)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user