Skip to content

Commit 5742bd3

Browse files
xiaoboxclaude
andcommitted
refactor: 优化数学公式渲染和清理无用代码
- 重构 math 模块:使用 MathJax SVG 直接渲染,不再转换为图片 - 简化复制流程:移除 isCopying 加载状态,优化剪贴板处理 - 清理 App.vue:删除调试日志、合并重复导入、移除注释代码 - 删除已弃用的 rasterizeMathFormulas 和 mathElementToImage 函数 - 更新数学公式样式和相关测试 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent cb3e5cb commit 5742bd3

16 files changed

Lines changed: 514 additions & 327 deletions

File tree

package-lock.json

Lines changed: 65 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
"codemirror": "^6.0.1",
4444
"electron-squirrel-startup": "^1.0.1",
4545
"github-markdown-css": "^5.8.1",
46-
"html2canvas": "^1.4.1",
47-
"katex": "^0.16.27",
46+
"mathjax-full": "^3.2.2",
4847
"mermaid": "^11.9.0",
4948
"prismjs": "^1.30.0",
5049
"svgo": "^4.0.0",

src/App.vue

Lines changed: 20 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,7 @@
4747
/>
4848

4949
<!-- 通知组件 -->
50-
<div v-if="notifications.length > 0 || isCopying" class="notification-container">
51-
<!-- 复制中 loading 通知 -->
52-
<div v-if="isCopying" class="notification loading">
53-
<span class="loading-spinner"></span>
54-
<span>正在处理内容...</span>
55-
</div>
50+
<div v-if="notifications.length > 0" class="notification-container">
5651
<div
5752
v-for="notification in notifications"
5853
:key="notification.id"
@@ -80,10 +75,8 @@
8075
</template>
8176

8277
<script setup>
83-
import { ref } from 'vue'
84-
import { useAppState, useElectron } from './composables/index.js'
85-
import { useGlobalThemeManager } from './composables/index.js'
86-
import { nextTick } from 'vue'
78+
import { ref, nextTick } from 'vue'
79+
import { useAppState, useElectron, useGlobalThemeManager } from './composables/index.js'
8780
import AppHeader from './components/layout/AppHeader.vue'
8881
import AppMain from './components/layout/AppMain.vue'
8982
import AppFooter from './components/layout/AppFooter.vue'
@@ -102,7 +95,6 @@ const {
10295
notifications,
10396
selectedCopyFormat,
10497
copyFormatOptions,
105-
isCopying,
10698
10799
// 计算属性
108100
hasContent,
@@ -138,79 +130,36 @@ const {
138130
139131
// 设置菜单监听器
140132
nextTick(() => {
141-
console.log('⏰ 在下一个tick中设置菜单监听器...');
142133
setupMenuListeners({
143-
onOpenFile: (event, { filePath, content }) => {
144-
console.log('📁 渲染进程收到打开文件事件');
145-
console.log('📂 文件路径:', filePath);
146-
147-
// 更新编辑器内容
148-
updateMarkdownContent(content);
149-
console.log('✅ 编辑器内容已更新');
150-
151-
// 设置当前文件路径(通过 openFile 函数)
152-
openFile(filePath, content);
153-
console.log('📁 当前文件路径已设置');
154-
155-
const fileName = filePath.split('/').pop() || filePath.split('\\').pop();
156-
console.log('🔔 显示成功通知:', fileName);
157-
showNotification(`已打开文件: ${fileName}`, 'success');
158-
159-
console.log('🎉 文件打开流程完成');
134+
onOpenFile: (_event, { filePath, content }) => {
135+
updateMarkdownContent(content)
136+
openFile(filePath, content)
137+
const fileName = filePath.split('/').pop() || filePath.split('\\').pop()
138+
showNotification(`已打开文件: ${fileName}`, 'success')
160139
},
161140
onSaveFile: async () => {
162-
console.log('💾 渲染进程收到保存文件事件');
163141
try {
164-
const result = await saveFile(markdownContent.value);
142+
const result = await saveFile(markdownContent.value)
165143
if (result.success) {
166-
console.log('✅ 文件保存成功:', result.filePath);
167-
const fileName = result.filePath.split('/').pop() || result.filePath.split('\\').pop();
168-
showNotification(`文件已保存: ${fileName}`, 'success');
144+
const fileName = result.filePath.split('/').pop() || result.filePath.split('\\').pop()
145+
showNotification(`文件已保存: ${fileName}`, 'success')
169146
} else {
170-
console.log('❌ 文件保存失败:', result.message);
171-
showNotification(`保存失败: ${result.message}`, 'error');
147+
showNotification(`保存失败: ${result.message}`, 'error')
172148
}
173149
} catch (error) {
174-
console.error('💥 保存文件时发生错误:', error);
175-
showNotification(`保存失败: ${error.message}`, 'error');
150+
showNotification(`保存失败: ${error.message}`, 'error')
176151
}
177152
}
178153
})
179-
154+
180155
// 设置文件内容更新监听器
181-
setupFileUpdateListener((event, { filePath, content }) => {
182-
console.log('📨 收到文件内容更新事件');
183-
console.log('📂 文件路径:', filePath);
184-
console.log('📄 新内容长度:', content.length);
185-
186-
// 检查是否是当前打开的文件
187-
if (currentFilePath.value === filePath) {
188-
console.log('🔄 更新当前文件内容...');
189-
190-
// 检查内容是否真的发生了变化
191-
if (markdownContent.value !== content) {
192-
// 更新编辑器内容
193-
updateMarkdownContent(content);
194-
console.log('✅ 编辑器内容已自动更新');
195-
196-
// 显示更新通知
197-
const fileName = filePath.split('/').pop() || filePath.split('\\').pop();
198-
showNotification(`文件已更新: ${fileName}`);
199-
200-
// 可选:记录更新日志
201-
console.log('📝 文件内容更新记录:', {
202-
filePath,
203-
oldLength: markdownContent.value.length,
204-
newLength: content.length,
205-
timestamp: new Date().toISOString()
206-
});
207-
} else {
208-
console.log('ℹ️ 内容相同,无需更新');
209-
}
210-
} else {
211-
console.log('ℹ️ 不是当前打开的文件,忽略更新:', filePath);
156+
setupFileUpdateListener((_event, { filePath, content }) => {
157+
if (currentFilePath.value === filePath && markdownContent.value !== content) {
158+
updateMarkdownContent(content)
159+
const fileName = filePath.split('/').pop() || filePath.split('\\').pop()
160+
showNotification(`文件已更新: ${fileName}`)
212161
}
213-
});
162+
})
214163
})
215164
216165
// 初始化主题管理器(全局单例内部已自动调用 initialize)
@@ -238,14 +187,6 @@ const handleFileChosen = async (e) => {
238187
}
239188
}
240189
241-
// 基于第一行 H1 自动生成文件名(导出功能移除后不再使用,可保留以备后续扩展)
242-
// const makeExportFilename = () => {
243-
// const md = markdownContent.value || ''
244-
// const h1Match = md.match(/^#\s+(.+?)\s*$/m)
245-
// const raw = (h1Match && h1Match[1]) || 'markdown-preview'
246-
// return raw.replace(/[\\/:*?"<>|]/g, '').replace(/\s+/g, ' ').trim().slice(0, 80) || 'markdown-preview'
247-
// }
248-
249190
</script>
250191

251192
<style scoped>

src/composables/useAppState.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ export function useAppState() {
8181
// 剪贴板功能 (来自 useClipboard)
8282
copyFormatOptions: clipboard.copyFormatOptions,
8383
selectedCopyFormat: clipboard.selectedCopyFormat,
84-
isCopying: clipboard.isCopying,
8584
handleCopyFormatSelect: clipboard.handleCopyFormatSelect,
8685

8786
// 其他功能

0 commit comments

Comments
 (0)