Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(paragraph): when switching from 2 lines to 1 line, the selection … #2997

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/docs-ui/src/views/paragraph-setting/hook/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import type { DocumentDataModel, IParagraph } from '@univerjs/core';
import { ICommandService, IUniverInstanceService, UniverInstanceType, useDependency } from '@univerjs/core';
import { getParagraphsInRanges, TextSelectionManagerService } from '@univerjs/docs';
import { useState } from 'react';
import { useMemo, useState } from 'react';
import { getNumberUnitValue } from '@univerjs/engine-render';
import type { IDocParagraphSettingCommandParams } from '../../../commands/commands/doc-paragraph-setting.command';
import { DocParagraphSettingCommand } from '../../../commands/commands/doc-paragraph-setting.command';
Expand All @@ -26,7 +26,12 @@ export const useCurrentParagraph = () => {
const textSelectionManagerService = useDependency(TextSelectionManagerService);
const univerInstanceService = useDependency(IUniverInstanceService);
const docDataModel = univerInstanceService.getCurrentUnitForType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC);
const docRanges = textSelectionManagerService.getDocRanges();
// The `getDocRanges` function internally needs to use `range.position` to obtain the offset.
// However, when the form control changes and triggers the `getDocRanges` function, the `Skeleton` has already been updated.
// The information of `range.position` in the textSelectionManagerService does not match the `Skeleton`, causing errors in value retrieval.
// To address this issue, adding useMemo here to only retrieve the range information for the first time to avoid mismatches between the `Skeleton` and `position`.
// TODO@GGGPOUND, the business side should not be aware of the timing issue with getDocRanges.
const docRanges = useMemo(() => textSelectionManagerService.getDocRanges(), []);

if (!docDataModel || docRanges.length === 0) {
return [];
Expand Down
Loading