From 346993b6cd53b40c0276a8b88a881c92a7c3f08f Mon Sep 17 00:00:00 2001 From: zw Date: Wed, 7 Aug 2024 20:14:03 +0800 Subject: [PATCH] fix: change list type --- packages/docs/src/commands/commands/list.command.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/docs/src/commands/commands/list.command.ts b/packages/docs/src/commands/commands/list.command.ts index 8687eeec60e..8c70a9998ac 100644 --- a/packages/docs/src/commands/commands/list.command.ts +++ b/packages/docs/src/commands/commands/list.command.ts @@ -221,13 +221,12 @@ export const ChangeListTypeCommand: ICommand = { const commandService = accessor.get(ICommandService); const { listType } = params; const docDataModel = univerInstanceService.getCurrentUniverDocInstance(); - const activeRange = textSelectionManagerService.getActiveTextRangeWithStyle(); - if (docDataModel == null || activeRange == null) { + const activeRanges = textSelectionManagerService.getDocRanges(); + if (docDataModel == null || activeRanges == null || !activeRanges.length) { return false; } - const { segmentId } = activeRange; - + const { segmentId } = activeRanges[0]; const selections = textSelectionManagerService.getDocRanges() ?? []; const paragraphs = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()?.paragraphs; const serializedSelections = selections.map(serializeDocRange); @@ -237,7 +236,7 @@ export const ChangeListTypeCommand: ICommand = { } const sectionBreaks = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()?.sectionBreaks ?? []; - const currentParagraphs = getParagraphsRelative(activeRange, paragraphs); + const currentParagraphs = getParagraphsRelative(activeRanges, paragraphs); const unitId = docDataModel.getUnitId(); const ID_LENGTH = 6; const listId = Tools.generateRandomId(ID_LENGTH); @@ -766,8 +765,8 @@ export function getParagraphsInRange(activeRange: IActiveTextRange, paragraphs: return results; } -export function getParagraphsRelative(activeRange: IActiveTextRange, paragraphs: IParagraph[]) { - const selectionParagraphs = getParagraphsInRange(activeRange, paragraphs); +export function getParagraphsRelative(ranges: IDocRange[], paragraphs: IParagraph[]) { + const selectionParagraphs = getParagraphsInRanges(ranges, paragraphs); const startIndex = paragraphs.indexOf(selectionParagraphs[0]); const endIndex = paragraphs.indexOf(selectionParagraphs[selectionParagraphs.length - 1]); if (selectionParagraphs[0].bullet) {