fix: 修复 markdown 编辑保存后内容丢失的问题
- 在 saveContent 中缓存 unsavedContent,避免 async 期间的竞态条件 - 在 useMarkdownLogic 中添加 lastContentRef 跟踪内容变化,防止不必要的编辑器更新
This commit is contained in:
@@ -331,7 +331,9 @@ export const useTabStore = create<TabStore>((set, get) => {
|
||||
const isAsyncImportProcessing = isAsyncImportProcessingContent(tab.content)
|
||||
if (isAsyncImportProcessing) return
|
||||
|
||||
await saveFileContent(filePath, tab.unsavedContent)
|
||||
const contentToSave = tab.unsavedContent
|
||||
|
||||
await saveFileContent(filePath, contentToSave)
|
||||
|
||||
set((state) => {
|
||||
const newTabs = new Map(state.tabs)
|
||||
@@ -339,7 +341,8 @@ export const useTabStore = create<TabStore>((set, get) => {
|
||||
if (currentTab) {
|
||||
newTabs.set(filePath, {
|
||||
...currentTab,
|
||||
content: currentTab.unsavedContent,
|
||||
content: contentToSave,
|
||||
unsavedContent: contentToSave,
|
||||
isEditing: false,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user