Skip to content

Commit 0587fc4

Browse files
committed
perf: 体验优化,现在末尾空行不再视为已改动
1 parent fe23048 commit 0587fc4

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/renderer/components/editor/MilkupEditor.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { useAIConfig } from "@/renderer/hooks/useAIConfig";
2121
import { useConfig } from "@/renderer/hooks/useConfig";
2222
import emitter from "@/renderer/events";
2323
import "@/core/styles/milkup.css";
24+
import { normalizeMarkdownForDirtyCheck } from "@/renderer/utils/markdown";
2425
2526
interface Props {
2627
tab: Tab;
@@ -195,7 +196,9 @@ function createEditorInstance() {
195196
return;
196197
}
197198
198-
tab.isModified = restoredMarkdown !== tab.originalContent;
199+
tab.isModified =
200+
normalizeMarkdownForDirtyCheck(restoredMarkdown) !==
201+
normalizeMarkdownForDirtyCheck(tab.originalContent);
199202
emitOutlineUpdate();
200203
});
201204

src/renderer/hooks/useTab.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { setCurrentMarkdownFilePath } from "@/plugins/imagePathPlugin";
77
import emitter from "@/renderer/events";
88
import { createTabDataFromFile, readAndProcessFile } from "@/renderer/services/fileService";
99
import { createInertiaScroll } from "@/renderer/utils/inertiaScroll";
10+
import { normalizeMarkdownForDirtyCheck } from "@/renderer/utils/markdown";
1011
import { randomUUID } from "@/renderer/utils/tool";
1112
import { isShowOutline } from "./useOutline";
1213
import { useConfig } from "./useConfig";
@@ -168,7 +169,6 @@ function updateCurrentTabContent(content: string, isModified?: boolean) {
168169
const currentTab = getCurrentTab();
169170
if (!currentTab) return;
170171

171-
const prevContent = currentTab.content;
172172
currentTab.content = content;
173173

174174
if (currentTab.readOnly) {
@@ -190,8 +190,9 @@ function updateCurrentTabContent(content: string, isModified?: boolean) {
190190
return;
191191
}
192192

193-
// 简单比较:当前内容 vs 原始内容
194-
currentTab.isModified = content !== currentTab.originalContent;
193+
currentTab.isModified =
194+
normalizeMarkdownForDirtyCheck(content) !==
195+
normalizeMarkdownForDirtyCheck(currentTab.originalContent);
195196
}
196197

197198
// 更新当前tab的文件信息(用于文件覆盖场景)

src/renderer/utils/markdown.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function normalizeMarkdownForDirtyCheck(content: string): string {
2+
return content.replace(/(?:\r?\n(?:[ \t]*\r?\n)*)[ \t]*$/u, "");
3+
}

0 commit comments

Comments
 (0)