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:
```javascript
instance.command.executeSetValue(payload: Partial<IEditorData>)
instance.command.executeSetValue(payload: Partial<IEditorData>, options?: ISetValueOption)
```
## executeRemoveControl

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

@ -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<IEditorData>) {
this.draw.setValue(payload)
public setValue(payload: Partial<IEditorData>, options?: ISetValueOption) {
this.draw.setValue(payload, options)
}
public removeControl() {

@ -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<IEditorData>) {
public setValue(payload: Partial<IEditorData>, 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
})
}

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

Loading…
Cancel
Save