@@ -587,9 +587,16 @@ describe('HeaderFooterSessionManager', () => {
587587 } ) ;
588588
589589 describe ( 'createDecorationProvider — resolved items' , ( ) => {
590- function buildHeaderResult ( options ?: { y ?: number ; minY ?: number ; blockId ?: string } ) : HeaderFooterLayoutResult {
590+ function buildHeaderResult ( options ?: {
591+ y ?: number ;
592+ minY ?: number ;
593+ blockId ?: string ;
594+ pageNumber ?: number ;
595+ type ?: HeaderFooterLayoutResult [ 'type' ] ;
596+ } ) : HeaderFooterLayoutResult {
591597 const y = options ?. y ?? 10 ;
592598 const blockId = options ?. blockId ?? 'p1' ;
599+ const pageNumber = options ?. pageNumber ?? 1 ;
593600 const paraFragment : ParaFragment = {
594601 kind : 'para' ,
595602 blockId,
@@ -602,7 +609,7 @@ describe('HeaderFooterSessionManager', () => {
602609 const layout : HeaderFooterLayout = {
603610 height : 50 ,
604611 ...( options ?. minY != null ? { minY : options . minY } : { } ) ,
605- pages : [ { number : 1 , fragments : [ paraFragment ] } ] ,
612+ pages : [ { number : pageNumber , fragments : [ paraFragment ] } ] ,
606613 } ;
607614 const blocks : FlowBlock [ ] = [ { kind : 'paragraph' , id : blockId , runs : [ ] } ] ;
608615 const measures : Measure [ ] = [
@@ -612,7 +619,7 @@ describe('HeaderFooterSessionManager', () => {
612619 totalHeight : 18 ,
613620 } ,
614621 ] ;
615- return { kind : 'header' , type : 'default' , layout, blocks, measures } ;
622+ return { kind : 'header' , type : options ?. type ?? 'default' , layout, blocks, measures } ;
616623 }
617624
618625 it ( 'delivers items aligned 1:1 with fragments when variant layout is used' , ( ) => {
@@ -772,6 +779,88 @@ describe('HeaderFooterSessionManager', () => {
772779 expect ( payload ! . items ! [ 0 ] ) . toMatchObject ( { blockId : 'p1' , x : 72 , y : 0 } ) ;
773780 } ) ;
774781
782+ it ( 'uses section titlePg state when selecting decoration-provider variants' , ( ) => {
783+ const deps : SessionManagerDependencies = {
784+ getLayoutOptions : vi . fn ( ( ) => ( { } ) ) ,
785+ getPageElement : vi . fn ( ( ) => null ) ,
786+ scrollPageIntoView : vi . fn ( ) ,
787+ waitForPageMount : vi . fn ( async ( ) => true ) ,
788+ convertPageLocalToOverlayCoords : vi . fn ( ( ) => ( { x : 0 , y : 0 } ) ) ,
789+ isViewLocked : vi . fn ( ( ) => false ) ,
790+ getBodyPageHeight : vi . fn ( ( ) => 800 ) ,
791+ notifyInputBridgeTargetChanged : vi . fn ( ) ,
792+ scheduleRerender : vi . fn ( ) ,
793+ setPendingDocChange : vi . fn ( ) ,
794+ getBodyPageCount : vi . fn ( ( ) => 2 ) ,
795+ } ;
796+
797+ manager = new HeaderFooterSessionManager ( {
798+ painterHost,
799+ visibleHost,
800+ selectionOverlay,
801+ editor : {
802+ ...createMainEditorStub ( ) ,
803+ converter : {
804+ headerIds : { titlePg : true } ,
805+ } ,
806+ } as unknown as Editor ,
807+ defaultPageSize : { w : 612 , h : 792 } ,
808+ defaultMargins : { top : 72 , right : 72 , bottom : 72 , left : 72 , header : 36 , footer : 36 } ,
809+ } ) ;
810+ manager . setDependencies ( deps ) ;
811+ manager . setMultiSectionIdentifier (
812+ buildMultiSectionIdentifier ( [
813+ {
814+ sectionIndex : 0 ,
815+ titlePg : true ,
816+ headerRefs : { first : 'rId-section0-first' , default : 'rId-section0-default' } ,
817+ } ,
818+ {
819+ sectionIndex : 1 ,
820+ titlePg : false ,
821+ headerRefs : { first : 'rId-section1-first' , default : 'rId-section1-default' } ,
822+ } ,
823+ ] ) ,
824+ ) ;
825+ manager . setLayoutResults (
826+ [
827+ buildHeaderResult ( { type : 'first' , blockId : 'first-block' , pageNumber : 2 } ) ,
828+ buildHeaderResult ( { type : 'default' , blockId : 'default-block' , pageNumber : 2 } ) ,
829+ ] ,
830+ null ,
831+ ) ;
832+
833+ const layout : Layout = {
834+ version : 1 ,
835+ flowMode : 'paginated' ,
836+ pageGap : 0 ,
837+ pageSize : { w : 612 , h : 792 } ,
838+ pages : [
839+ {
840+ number : 1 ,
841+ sectionIndex : 0 ,
842+ margins : { top : 72 , right : 72 , bottom : 72 , left : 72 , header : 36 , footer : 36 } ,
843+ } ,
844+ {
845+ number : 2 ,
846+ sectionIndex : 1 ,
847+ margins : { top : 72 , right : 72 , bottom : 72 , left : 72 , header : 36 , footer : 36 } ,
848+ sectionRefs : {
849+ headerRefs : { first : 'rId-section1-first' , default : 'rId-section1-default' } ,
850+ footerRefs : { } ,
851+ } ,
852+ } ,
853+ ] as never ,
854+ } as unknown as Layout ;
855+
856+ const provider = manager . createDecorationProvider ( 'header' , layout as unknown as ResolvedLayout ) ;
857+ const payload = provider ! ( 2 , layout . pages [ 1 ] ! . margins , layout . pages [ 1 ] as unknown as ResolvedPage ) ;
858+
859+ expect ( payload ) . not . toBeNull ( ) ;
860+ expect ( payload ! . sectionType ) . toBe ( 'default' ) ;
861+ expect ( payload ! . items ! [ 0 ] ! . blockId ) . toBe ( 'default-block' ) ;
862+ } ) ;
863+
775864 it ( 'normalizes resolved items when per-rId layout minY is negative' , async ( ) => {
776865 mockLayoutPerRIdHeaderFooters . mockImplementation (
777866 async (
0 commit comments