Skip to content

Commit

Permalink
fix: header footer checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocs committed Oct 17, 2024
1 parent 3a68274 commit d1c2d70
Showing 1 changed file with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import type { IDocumentStyle } from '@univerjs/core';
import { BooleanNumber, ICommandService, IUniverInstanceService, LocaleService, Tools, useDependency } from '@univerjs/core';
import { Button, Checkbox, InputNumber } from '@univerjs/design';
import { DocSelectionManagerService, DocSkeletonManagerService } from '@univerjs/docs';
Expand All @@ -25,6 +26,32 @@ import { CoreHeaderFooterCommandId, type IHeaderFooterProps } from '../../../com
import { DocSelectionRenderService } from '../../../services/selection/doc-selection-render.service';
import styles from './index.module.less';

function getSegmentId(documentStyle: IDocumentStyle, editArea: DocumentEditArea, pageIndex: number): string {
const { useFirstPageHeaderFooter, evenAndOddHeaders, defaultHeaderId, defaultFooterId, firstPageHeaderId, firstPageFooterId, evenPageHeaderId, evenPageFooterId } = documentStyle;

if (editArea === DocumentEditArea.HEADER) {
if (useFirstPageHeaderFooter === BooleanNumber.TRUE) {
if (pageIndex === 0) {
return firstPageHeaderId!;
} else {
return evenAndOddHeaders === BooleanNumber.TRUE && pageIndex % 2 === 1 ? evenPageHeaderId! : defaultHeaderId!;
}
} else {
return evenAndOddHeaders === BooleanNumber.TRUE && pageIndex % 2 === 1 ? evenPageHeaderId! : defaultHeaderId!;
}
} else {
if (useFirstPageHeaderFooter === BooleanNumber.TRUE) {
if (pageIndex === 0) {
return firstPageFooterId!;
} else {
return evenAndOddHeaders === BooleanNumber.TRUE && pageIndex % 2 === 1 ? evenPageFooterId! : defaultFooterId!;
}
} else {
return evenAndOddHeaders === BooleanNumber.TRUE && pageIndex % 2 === 1 ? evenPageFooterId! : defaultFooterId!;
}
}
}

export interface IDocHeaderFooterOptionsProps {
unitId: string;
}
Expand Down Expand Up @@ -102,23 +129,17 @@ export const DocHeaderFooterOptions = (props: IDocHeaderFooterOptionsProps) => {
},
});
} else {
let needFocusSegmentId;
const segmentPageIndex = docSelectionRenderService.getSegmentPage();
const prevSegmentId = docSelectionRenderService.getSegment();

if (type === 'useFirstPageHeaderFooter') {
if (editArea === DocumentEditArea.HEADER) {
needFocusSegmentId = val && segmentPageIndex === 0 ? documentStyle.firstPageHeaderId : documentStyle.defaultHeaderId;
} else if (editArea === DocumentEditArea.FOOTER) {
needFocusSegmentId = val && segmentPageIndex === 0 ? documentStyle.firstPageFooterId : documentStyle.defaultFooterId;
}
} else if (type === 'evenAndOddHeaders') {
if (editArea === DocumentEditArea.HEADER) {
needFocusSegmentId = val && segmentPageIndex % 2 === 1 ? documentStyle.evenPageHeaderId : documentStyle.defaultHeaderId;
} else if (editArea === DocumentEditArea.FOOTER) {
needFocusSegmentId = val && segmentPageIndex % 2 === 1 ? documentStyle.evenPageFooterId : documentStyle.defaultFooterId;
}
}
const needFocusSegmentId = getSegmentId(
{
...documentStyle,
[type]: val ? BooleanNumber.TRUE : BooleanNumber.FALSE,
},
editArea,
segmentPageIndex
);

if (needFocusSegmentId && needFocusSegmentId !== prevSegmentId) {
docSelectionRenderService.setSegment(needFocusSegmentId);
Expand Down

0 comments on commit d1c2d70

Please sign in to comment.