From 535562e396ce150916456a0ed791edc4ff208de4 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Tue, 9 May 2023 21:00:07 +0800 Subject: [PATCH] feat: location catalog api --- src/editor/core/command/Command.ts | 6 ++++++ src/editor/core/command/CommandAdapt.ts | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/editor/core/command/Command.ts b/src/editor/core/command/Command.ts index a092408..dddbaa5 100644 --- a/src/editor/core/command/Command.ts +++ b/src/editor/core/command/Command.ts @@ -87,6 +87,7 @@ export class Command { private static removeControl: CommandAdapt['removeControl'] private static setLocale: CommandAdapt['setLocale'] private static getCatalog: CommandAdapt['getCatalog'] + private static locationCatalog: CommandAdapt['locationCatalog'] constructor(adapt: CommandAdapt) { Command.mode = adapt.mode.bind(adapt) @@ -166,6 +167,7 @@ export class Command { Command.removeControl = adapt.removeControl.bind(adapt) Command.setLocale = adapt.setLocale.bind(adapt) Command.getCatalog = adapt.getCatalog.bind(adapt) + Command.locationCatalog = adapt.locationCatalog.bind(adapt) } // 全局命令 @@ -483,4 +485,8 @@ export class Command { return Command.getCatalog() } + public executeLocationCatalog(titleId: string) { + return Command.locationCatalog(titleId) + } + } \ No newline at end of file diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index 0c0d139..2094051 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -1660,4 +1660,23 @@ export class CommandAdapt { return this.workerManager.getCatalog() } + public locationCatalog(titleId: string) { + const elementList = this.draw.getMainElementList() + let newIndex = -1 + for (let e = 0; e < elementList.length; e++) { + const element = elementList[e] + if (element.titleId === titleId && elementList[e + 1]?.titleId !== titleId) { + newIndex = e + break + } + } + if (!~newIndex) return + this.range.setRange(newIndex, newIndex) + this.draw.render({ + curIndex: newIndex, + isCompute: false, + isSubmitHistory: false + }) + } + } \ No newline at end of file