diff --git a/docs/en/guide/command-execute.md b/docs/en/guide/command-execute.md index 7b0cd77..f1a6d35 100644 --- a/docs/en/guide/command-execute.md +++ b/docs/en/guide/command-execute.md @@ -789,7 +789,7 @@ Feature: Set the editor data Usage: ```javascript -instance.command.executeSetValue(payload: Partial) +instance.command.executeSetValue(payload: Partial, options?: ISetValueOption) ``` ## executeRemoveControl diff --git a/docs/guide/command-execute.md b/docs/guide/command-execute.md index edd3da2..c62ad20 100644 --- a/docs/guide/command-execute.md +++ b/docs/guide/command-execute.md @@ -789,7 +789,7 @@ instance.command.executeUpdateElementById(payload: IUpdateElementByIdOption) 用法: ```javascript -instance.command.executeSetValue(payload: Partial) +instance.command.executeSetValue(payload: Partial, options?: ISetValueOption) ``` ## executeRemoveControl diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index a957f63..799ec0e 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -51,6 +51,7 @@ import { IEditorOption, IEditorResult, IEditorText, + ISetValueOption, IUpdateOption } from '../../interface/Editor' import { @@ -2301,8 +2302,8 @@ export class CommandAdapt { } } - public setValue(payload: Partial) { - this.draw.setValue(payload) + public setValue(payload: Partial, options?: ISetValueOption) { + this.draw.setValue(payload, options) } public removeControl() { diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index a3f851b..f5d5dfd 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -15,7 +15,8 @@ import { import { IEditorData, IEditorOption, - IEditorResult + IEditorResult, + ISetValueOption } from '../../interface/Editor' import { IElement, @@ -1034,9 +1035,10 @@ export class Draw { } } - public setValue(payload: Partial) { + public setValue(payload: Partial, options?: ISetValueOption) { const { header, main, footer } = deepClone(payload) if (!header && !main && !footer) return + const { isSetCursor = false } = options || {} const pageComponentData = [header, main, footer] pageComponentData.forEach(data => { if (!data) return @@ -1051,8 +1053,17 @@ export class Draw { }) // 渲染&计算&清空历史记录 this.historyManager.recovery() + const curIndex = isSetCursor + ? main?.length + ? main.length - 1 + : 0 + : undefined + if (curIndex !== undefined) { + this.range.setRange(curIndex, curIndex) + } this.render({ - isSetCursor: false, + curIndex, + isSetCursor, isFirstRender: true }) } diff --git a/src/editor/interface/Editor.ts b/src/editor/interface/Editor.ts index ca1495b..0dcb176 100644 --- a/src/editor/interface/Editor.ts +++ b/src/editor/interface/Editor.ts @@ -117,3 +117,7 @@ export type IUpdateOption = Omit< | 'historyMaxRecordCount' | 'scrollContainerSelector' > + +export interface ISetValueOption { + isSetCursor?: boolean +}