Skip to content

Commit 9ed22de

Browse files
committed
fix(math): prevent editor resets while typing
1 parent 3b55f45 commit 9ed22de

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/renderer/composables/__tests__/useMathNotebook.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
22
import { computed, ref } from 'vue'
33

44
const invoke = vi.fn()
5+
const markPersistedStorageMutation = vi.fn()
6+
const markUserEdit = vi.fn()
57

68
globalThis.ref = ref
79
globalThis.computed = computed
@@ -16,7 +18,8 @@ vi.mock('@/electron', () => ({
1618
}))
1719

1820
vi.mock('@/composables/useStorageMutation', () => ({
19-
markPersistedStorageMutation: vi.fn(),
21+
markPersistedStorageMutation,
22+
markUserEdit,
2023
}))
2124

2225
describe('useMathNotebook', () => {
@@ -43,4 +46,18 @@ describe('useMathNotebook', () => {
4346

4447
expect(invoke).toHaveBeenCalledTimes(2)
4548
})
49+
50+
it('marks user edit when sheet content changes', async () => {
51+
const { useMathNotebook } = await import(
52+
'../math-notebook/useMathNotebook'
53+
)
54+
const notebook = useMathNotebook()
55+
56+
await notebook.init()
57+
58+
const sheetId = notebook.createSheet()
59+
notebook.updateSheet(sheetId, '1 + 1')
60+
61+
expect(markUserEdit).toHaveBeenCalledTimes(1)
62+
})
4663
})

src/renderer/composables/math-notebook/useMathNotebook.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import type { MathSheet } from '~/main/store/types'
2-
import { markPersistedStorageMutation } from '@/composables/useStorageMutation'
2+
import {
3+
markPersistedStorageMutation,
4+
markUserEdit,
5+
} from '@/composables/useStorageMutation'
36
import { i18n, ipc } from '@/electron'
47
import { useDebounceFn } from '@vueuse/core'
58
import { nanoid } from 'nanoid'
@@ -113,6 +116,7 @@ export function useMathNotebook() {
113116
function updateSheet(id: string, content: string) {
114117
const sheet = sheets.value.find(s => s.id === id)
115118
if (sheet) {
119+
markUserEdit()
116120
sheet.content = content
117121
sheet.updatedAt = Date.now()
118122
debouncedPersist()

0 commit comments

Comments
 (0)