feat: add cursor setting option to executeSetValue api #715

npr765
Hufe921 2 years ago
parent f5113f539c
commit 3235e5ae38

@ -789,7 +789,7 @@ Feature: Set the editor data
Usage: Usage:
```javascript ```javascript
instance.command.executeSetValue(payload: Partial<IEditorData>) instance.command.executeSetValue(payload: Partial<IEditorData>, options?: ISetValueOption)
``` ```
## executeRemoveControl ## executeRemoveControl

@ -789,7 +789,7 @@ instance.command.executeUpdateElementById(payload: IUpdateElementByIdOption)
用法: 用法:
```javascript ```javascript
instance.command.executeSetValue(payload: Partial<IEditorData>) instance.command.executeSetValue(payload: Partial<IEditorData>, options?: ISetValueOption)
``` ```
## executeRemoveControl ## executeRemoveControl

@ -51,6 +51,7 @@ import {
IEditorOption, IEditorOption,
IEditorResult, IEditorResult,
IEditorText, IEditorText,
ISetValueOption,
IUpdateOption IUpdateOption
} from '../../interface/Editor' } from '../../interface/Editor'
import { import {
@ -2301,8 +2302,8 @@ export class CommandAdapt {
} }
} }
public setValue(payload: Partial<IEditorData>) { public setValue(payload: Partial<IEditorData>, options?: ISetValueOption) {
this.draw.setValue(payload) this.draw.setValue(payload, options)
} }
public removeControl() { public removeControl() {

@ -15,7 +15,8 @@ import {
import { import {
IEditorData, IEditorData,
IEditorOption, IEditorOption,
IEditorResult IEditorResult,
ISetValueOption
} from '../../interface/Editor' } from '../../interface/Editor'
import { import {
IElement, IElement,
@ -1034,9 +1035,10 @@ export class Draw {
} }
} }
public setValue(payload: Partial<IEditorData>) { public setValue(payload: Partial<IEditorData>, options?: ISetValueOption) {
const { header, main, footer } = deepClone(payload) const { header, main, footer } = deepClone(payload)
if (!header && !main && !footer) return if (!header && !main && !footer) return
const { isSetCursor = false } = options || {}
const pageComponentData = [header, main, footer] const pageComponentData = [header, main, footer]
pageComponentData.forEach(data => { pageComponentData.forEach(data => {
if (!data) return if (!data) return
@ -1051,8 +1053,17 @@ export class Draw {
}) })
// 渲染&计算&清空历史记录 // 渲染&计算&清空历史记录
this.historyManager.recovery() this.historyManager.recovery()
const curIndex = isSetCursor
? main?.length
? main.length - 1
: 0
: undefined
if (curIndex !== undefined) {
this.range.setRange(curIndex, curIndex)
}
this.render({ this.render({
isSetCursor: false, curIndex,
isSetCursor,
isFirstRender: true isFirstRender: true
}) })
} }

@ -117,3 +117,7 @@ export type IUpdateOption = Omit<
| 'historyMaxRecordCount' | 'historyMaxRecordCount'
| 'scrollContainerSelector' | 'scrollContainerSelector'
> >
export interface ISetValueOption {
isSetCursor?: boolean
}

Loading…
Cancel
Save