@@ -200,6 +200,33 @@ describe('reading mode', () => {
200200 expect ( muya . getMarkdown ( ) ) . toContain ( 'original' ) ;
201201 } ) ;
202202
203+ it . each ( [ 'muya' , 'selection' ] as const ) ( 'selects the whole reading document through %s without editing selection side effects' , ( entry ) => {
204+ const muya = boot ( '| a | b |\n| --- | --- |\n| c | d |\n\nLast paragraph' , true ) ;
205+ const first = muya . editor . scrollPage ! . firstContentInDescendant ( ) ! ;
206+ const last = muya . editor . scrollPage ! . lastContentInDescendant ( ) ! ;
207+ const state = muya . getState ( ) ;
208+ const history = muya . getHistory ( ) ;
209+ const changed = vi . fn ( ) ;
210+ muya . on ( 'selection-change' , changed ) ;
211+ const setSelection = vi . spyOn ( muya . editor . selection , 'setSelection' ) ;
212+
213+ if ( entry === 'muya' )
214+ muya . selectAll ( ) ;
215+ else
216+ muya . editor . selection . selectAll ( ) ;
217+
218+ const range = document . getSelection ( ) ! . getRangeAt ( 0 ) ;
219+ expect ( range . startContainer ) . toBe ( first . domNode ) ;
220+ expect ( range . startOffset ) . toBe ( 0 ) ;
221+ expect ( range . endContainer ) . toBe ( last . domNode ) ;
222+ expect ( range . endOffset ) . toBe ( last . domNode ! . childNodes . length ) ;
223+ expect ( muya . editor . selection . table . hasSelection ) . toBe ( false ) ;
224+ expect ( setSelection ) . not . toHaveBeenCalled ( ) ;
225+ expect ( changed ) . not . toHaveBeenCalled ( ) ;
226+ expect ( muya . getState ( ) ) . toEqual ( state ) ;
227+ expect ( muya . getHistory ( ) ) . toEqual ( history ) ;
228+ } ) ;
229+
203230 it ( 'copies Markdown through the existing clipboard pipeline while reading' , ( ) => {
204231 const muya = boot ( '**hello** and [link](https://example.com)' , true ) ;
205232 muya . selectAll ( ) ;
0 commit comments