@@ -4,6 +4,8 @@ import { PresentationEditor } from '../PresentationEditor.js';
44import type { Editor as EditorInstance } from '../../Editor.js' ;
55import { Editor } from '../../Editor.js' ;
66import { HeaderFooterEditorManager , HeaderFooterLayoutAdapter } from '../../header-footer/HeaderFooterRegistry.js' ;
7+ import * as CaretGeometry from '../selection/CaretGeometry.js' ;
8+ import * as DomSelectionGeometry from '../../../dom-observer/DomSelectionGeometry.js' ;
79
810type MockedEditor = Mock < ( ...args : unknown [ ] ) => EditorInstance > & {
911 mock : {
@@ -3785,6 +3787,68 @@ describe('PresentationEditor', () => {
37853787 } ) ;
37863788 } ) ;
37873789
3790+ describe ( '#computeCaretLayoutRect DOM/geometry mismatch fallback' , ( ) => {
3791+ it ( 'uses DOM caret when DOM and geometry are close' , ( ) => {
3792+ const geometrySpy = vi
3793+ . spyOn ( CaretGeometry , 'computeCaretLayoutRectGeometry' )
3794+ . mockReturnValue ( { pageIndex : 0 , x : 100 , y : 200 , height : 18 } ) ;
3795+ const domSpy = vi
3796+ . spyOn ( DomSelectionGeometry , 'computeDomCaretPageLocal' )
3797+ . mockReturnValue ( { pageIndex : 0 , x : 108 , y : 210 } ) ;
3798+
3799+ editor = new PresentationEditor ( {
3800+ element : container ,
3801+ documentId : 'test-doc' ,
3802+ } ) ;
3803+
3804+ const caret = editor . computeCaretLayoutRect ( 5 ) ;
3805+ expect ( caret ) . toEqual ( { pageIndex : 0 , x : 108 , y : 210 , height : 18 } ) ;
3806+
3807+ geometrySpy . mockRestore ( ) ;
3808+ domSpy . mockRestore ( ) ;
3809+ } ) ;
3810+
3811+ it ( 'falls back to geometry when DOM and geometry differ significantly' , ( ) => {
3812+ const geometrySpy = vi
3813+ . spyOn ( CaretGeometry , 'computeCaretLayoutRectGeometry' )
3814+ . mockReturnValue ( { pageIndex : 0 , x : 100 , y : 200 , height : 18 } ) ;
3815+ const domSpy = vi
3816+ . spyOn ( DomSelectionGeometry , 'computeDomCaretPageLocal' )
3817+ . mockReturnValue ( { pageIndex : 0 , x : 180 , y : 290 } ) ;
3818+
3819+ editor = new PresentationEditor ( {
3820+ element : container ,
3821+ documentId : 'test-doc' ,
3822+ } ) ;
3823+
3824+ const caret = editor . computeCaretLayoutRect ( 5 ) ;
3825+ expect ( caret ) . toEqual ( { pageIndex : 0 , x : 100 , y : 200 , height : 18 } ) ;
3826+
3827+ geometrySpy . mockRestore ( ) ;
3828+ domSpy . mockRestore ( ) ;
3829+ } ) ;
3830+
3831+ it ( 'falls back to geometry when DOM and geometry point to different pages' , ( ) => {
3832+ const geometrySpy = vi
3833+ . spyOn ( CaretGeometry , 'computeCaretLayoutRectGeometry' )
3834+ . mockReturnValue ( { pageIndex : 1 , x : 120 , y : 220 , height : 16 } ) ;
3835+ const domSpy = vi
3836+ . spyOn ( DomSelectionGeometry , 'computeDomCaretPageLocal' )
3837+ . mockReturnValue ( { pageIndex : 0 , x : 120 , y : 220 } ) ;
3838+
3839+ editor = new PresentationEditor ( {
3840+ element : container ,
3841+ documentId : 'test-doc' ,
3842+ } ) ;
3843+
3844+ const caret = editor . computeCaretLayoutRect ( 5 ) ;
3845+ expect ( caret ) . toEqual ( { pageIndex : 1 , x : 120 , y : 220 , height : 16 } ) ;
3846+
3847+ geometrySpy . mockRestore ( ) ;
3848+ domSpy . mockRestore ( ) ;
3849+ } ) ;
3850+ } ) ;
3851+
37883852 describe ( '#updateSelection DOM manipulation error handling' , ( ) => {
37893853 it ( 'should handle DOM errors when clearing selection in viewing mode' , ( ) => {
37903854 editor = new PresentationEditor ( {
0 commit comments