Commit c7097fff by pangchong

style(editor): 优化代码格式与简洁性

- 统一箭头函数参数括号使用
- 删除多余空行,优化代码间距
- 合并 CommonXmlEditor 组件标签为单行简写形式
- 简化条件表达式,提高代码可读性
- 删除函数文件中多余空行
parent 868627e6
...@@ -161,11 +161,11 @@ export function formatXmlText(xmlStr: string): string { ...@@ -161,11 +161,11 @@ export function formatXmlText(xmlStr: string): string {
const cleanXml = xmlStr.trim().replace(/>\s+</g, '><') const cleanXml = xmlStr.trim().replace(/>\s+</g, '><')
// 正则分割标签与文本内容 // 正则分割标签与文本内容
const tokens = cleanXml.split(/(<[^>]+>)/g).filter(t => t.trim() !== '') const tokens = cleanXml.split(/(<[^>]+>)/g).filter((t) => t.trim() !== '')
let indentLevel = 0 let indentLevel = 0
const lines: string[] = [] const lines: string[] = []
for (let i = 0; i < tokens.length; i++) { for (let i = 0; i < tokens.length; i++) {
const token = tokens[i].trim() const token = tokens[i].trim()
if (!token) continue if (!token) continue
...@@ -184,10 +184,10 @@ export function formatXmlText(xmlStr: string): string { ...@@ -184,10 +184,10 @@ export function formatXmlText(xmlStr: string): string {
// 开始标签 // 开始标签
const matchTag = token.match(/^<([a-zA-Z0-9_:-]+)/) const matchTag = token.match(/^<([a-zA-Z0-9_:-]+)/)
const tagName = matchTag ? matchTag[1] : null const tagName = matchTag ? matchTag[1] : null
const nextToken = tokens[i + 1]?.trim() const nextToken = tokens[i + 1]?.trim()
const afterNextToken = tokens[i + 2]?.trim() const afterNextToken = tokens[i + 2]?.trim()
// 检查这是否是一个单行标签(即:开始标签 + 纯文本内容 + 结束标签) // 检查这是否是一个单行标签(即:开始标签 + 纯文本内容 + 结束标签)
if (tagName && nextToken && !nextToken.startsWith('<') && afterNextToken === `</${tagName}>`) { if (tagName && nextToken && !nextToken.startsWith('<') && afterNextToken === `</${tagName}>`) {
lines.push(' '.repeat(indentLevel) + token + nextToken + afterNextToken) lines.push(' '.repeat(indentLevel) + token + nextToken + afterNextToken)
......
...@@ -25,7 +25,7 @@ export function useInsertFragmentModal() { ...@@ -25,7 +25,7 @@ export function useInsertFragmentModal() {
if (text && text.trim()) { if (text && text.trim()) {
// 如果剪贴板内容含有 XML 标签,自动格式化后再填入 // 如果剪贴板内容含有 XML 标签,自动格式化后再填入
const raw = text.trim() const raw = text.trim()
xmlContent.value = (raw.includes('<') || raw.includes('>')) ? formatXmlText(raw) : raw xmlContent.value = raw.includes('<') || raw.includes('>') ? formatXmlText(raw) : raw
hasClipboardContent.value = true hasClipboardContent.value = true
} }
} }
......
import { useStashStore, type StashItem } from '@/store/stash' import { useStashStore, type StashItem } from '@/store/stash'
import { useEditorStore } from '@/store/editor' import { useEditorStore } from '@/store/editor'
export function useStashModal() { export function useStashModal() {
const visible = ref(false) const visible = ref(false)
const stashStore = useStashStore() const stashStore = useStashStore()
......
...@@ -145,11 +145,7 @@ ...@@ -145,11 +145,7 @@
<div class="h-3 bg-fill-3 rounded w-2/3"></div> <div class="h-3 bg-fill-3 rounded w-2/3"></div>
</div> </div>
<div v-else class="flex-grow min-h-0 flex flex-col"> <div v-else class="flex-grow min-h-0 flex flex-col">
<CommonXmlEditor <CommonXmlEditor v-model="activeItemXmlText" disabled height="100%" />
v-model="activeItemXmlText"
disabled
height="100%"
/>
</div> </div>
<!-- 操作面板 --> <!-- 操作面板 -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment