11import { afterEach , describe , expect , it , vi } from "vitest" ;
22
3+ import { waitFor } from "@testing-library/react" ;
4+
35import { runEditorCommand } from "@/features/editor/utils/editorCommands" ;
4- import { mountMilkdownEditor , type MountedMilkdownEditor } from "@/test/utils/milkdown" ;
6+ import {
7+ mountMilkdownEditor ,
8+ type MountedMilkdownEditor ,
9+ type MountMilkdownEditorOptions ,
10+ } from "@/test/utils/milkdown" ;
511import {
612 pressKey ,
713 setSelectionAtDocumentEnd ,
@@ -17,15 +23,21 @@ const mountedEditors: MountedMilkdownEditor[] = [];
1723const mountEditor = async (
1824 initialMarkdown : string ,
1925 onContentTransaction = vi . fn ( ) ,
26+ onMarkdownUpdated ?: MountMilkdownEditorOptions [ "onMarkdownUpdated" ] ,
2027) : Promise < MountedMilkdownEditor > => {
2128 const mounted = await mountMilkdownEditor ( initialMarkdown , {
2229 onContentTransaction,
30+ onMarkdownUpdated,
2331 rootClassName : "leafdown-editor" ,
2432 } ) ;
2533 mountedEditors . push ( mounted ) ;
2634 return mounted ;
2735} ;
2836
37+ const waitForMarkdownListenerDebounce = async ( ) => {
38+ await new Promise ( ( resolve ) => setTimeout ( resolve , 300 ) ) ;
39+ } ;
40+
2941const enterProjection = ( mounted : MountedMilkdownEditor , selector : "em" | "strong" ) => {
3042 const element = mounted . view . dom . querySelector ( selector ) ;
3143
@@ -167,6 +179,30 @@ describe("inline source projection", () => {
167179 expect ( hasActiveInlineSourceProjection ( mounted . view . state ) ) . toBe ( false ) ;
168180 } ) ;
169181
182+ it ( "does not emit transient projected source through markdown updates" , async ( ) => {
183+ const onMarkdownUpdated = vi . fn ( ) ;
184+ const mounted = await mountEditor ( "**Bold** plain" , vi . fn ( ) , onMarkdownUpdated ) ;
185+
186+ enterProjection ( mounted , "strong" ) ;
187+ await waitForMarkdownListenerDebounce ( ) ;
188+
189+ expect ( onMarkdownUpdated ) . not . toHaveBeenCalled ( ) ;
190+
191+ typeText ( mounted . view , "er" ) ;
192+ await waitForMarkdownListenerDebounce ( ) ;
193+
194+ expect ( onMarkdownUpdated ) . not . toHaveBeenCalled ( ) ;
195+
196+ setSelectionAtDocumentEnd ( mounted . view ) ;
197+
198+ await waitFor ( ( ) => {
199+ expect ( onMarkdownUpdated ) . toHaveBeenCalledWith (
200+ expect . objectContaining ( { markdown : "**Bolder** plain\n" } ) ,
201+ ) ;
202+ } ) ;
203+ expect ( onMarkdownUpdated ) . toHaveBeenCalledTimes ( 1 ) ;
204+ } ) ;
205+
170206 it ( "uses projection-local undo and redo while projection is active" , async ( ) => {
171207 const mounted = await mountEditor ( "**Bold** plain" ) ;
172208
0 commit comments