From 6f690a805ff385ce4e6ed3959285ceeb730567bf Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Mon, 8 Apr 2024 21:11:28 +0800 Subject: [PATCH] fix: add context param to the shrinkBoundary function #503 --- src/editor/core/draw/control/Control.ts | 4 ++-- src/editor/core/draw/control/text/TextControl.ts | 2 +- src/editor/core/range/RangeManager.ts | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/editor/core/draw/control/Control.ts b/src/editor/core/draw/control/Control.ts index 56f8134..1da5020 100644 --- a/src/editor/core/draw/control/Control.ts +++ b/src/editor/core/draw/control/Control.ts @@ -197,8 +197,8 @@ export class Control { return this.range.getRange() } - public shrinkBoundary() { - this.range.shrinkBoundary() + public shrinkBoundary(context: IControlContext = {}) { + this.range.shrinkBoundary(context) } public getActiveControl(): IControlInstance | null { diff --git a/src/editor/core/draw/control/text/TextControl.ts b/src/editor/core/draw/control/text/TextControl.ts index 1ac4231..7bd98b4 100644 --- a/src/editor/core/draw/control/text/TextControl.ts +++ b/src/editor/core/draw/control/text/TextControl.ts @@ -74,7 +74,7 @@ export class TextControl implements IControlInstance { const elementList = context.elementList || this.control.getElementList() const range = context.range || this.control.getRange() // 收缩边界到Value内 - this.control.shrinkBoundary() + this.control.shrinkBoundary(context) const { startIndex, endIndex } = range const draw = this.control.getDraw() // 移除选区元素 diff --git a/src/editor/core/range/RangeManager.ts b/src/editor/core/range/RangeManager.ts index b0b0686..f591644 100644 --- a/src/editor/core/range/RangeManager.ts +++ b/src/editor/core/range/RangeManager.ts @@ -3,6 +3,7 @@ import { ZERO } from '../../dataset/constant/Common' import { TEXTLIKE_ELEMENT_TYPE } from '../../dataset/constant/Element' import { ControlComponent } from '../../dataset/enum/Control' import { EditorContext } from '../../dataset/enum/Editor' +import { IControlContext } from '../../interface/Control' import { IEditorOption } from '../../interface/Editor' import { IElement } from '../../interface/Element' import { EventBusMap } from '../../interface/EventBus' @@ -480,9 +481,9 @@ export class RangeManager { } } - public shrinkBoundary() { - const elementList = this.draw.getElementList() - const range = this.getRange() + public shrinkBoundary(context: IControlContext = {}) { + const elementList = context.elementList || this.draw.getElementList() + const range = context.range || this.getRange() const { startIndex, endIndex } = range if (!~startIndex && !~endIndex) return const startElement = elementList[startIndex]