@@ -10,6 +10,7 @@ import {
1010import type { ServerProviderSkill } from "@t3tools/contracts" ;
1111import type { Editor } from "@tiptap/core" ;
1212import { redoDepth , undoDepth } from "@tiptap/pm/history" ;
13+ import { NodeSelection } from "@tiptap/pm/state" ;
1314import { createElement , createRef , useEffect , useState } from "react" ;
1415import { describe , expect , it , vi } from "vite-plus/test" ;
1516import { userEvent } from "vite-plus/test/browser" ;
@@ -351,6 +352,27 @@ async function focusAt(editor: Editor, position: number | "end") {
351352}
352353
353354describe ( "Markdown markers around styled text" , ( ) => {
355+ it . each ( [
356+ { keys : "{Backspace}" , expected : "**** after" } ,
357+ { keys : "X" , expected : "**X** after" } ,
358+ ] ) ( "keeps a styled chip selected for $keys when showing source" , async ( { keys, expected } ) => {
359+ await using screen = await mountEditor ( "$babysit after" , true , [ babysit ] ) ;
360+ const { editor } = screen ;
361+ await focusAt ( editor , "end" ) ;
362+ await act ( async ( ) => {
363+ editor . view . dispatch ( editor . state . tr . addMark ( 1 , 2 , editor . schema . marks . bold ! . create ( ) ) ) ;
364+ } ) ;
365+ expect ( editor . state . doc . nodeAt ( 1 ) ?. type . name ) . toBe ( "composer-skill" ) ;
366+ await act ( async ( ) => {
367+ editor . commands . setNodeSelection ( 1 ) ;
368+ } ) ;
369+ expect ( editor . state . selection ) . toBeInstanceOf ( NodeSelection ) ;
370+ expect ( ( editor . state . selection as NodeSelection ) . node . type . name ) . toBe ( "composer-skill" ) ;
371+ await userEvent . keyboard ( keys ) ;
372+ await userEvent . keyboard ( "{End}" ) ;
373+ await vi . waitFor ( ( ) => expect ( serializeEditorDoc ( editor . state . doc ) . value ) . toBe ( expected ) ) ;
374+ } ) ;
375+
354376 it . each ( [
355377 {
356378 name : "deleting the opening markers removes bold" ,
0 commit comments