Skip to content

Commit

Permalink
feat: add forceUpdate api #263
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Aug 27, 2023
1 parent 9fcbecc commit bc2f445
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/en/guide/command-execute.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ Usage:
instance.command.executeSetRange(startIndex: number , endIndex: number)
```

## executeForceUpdate

Feature: force update editor

Usage:

```javascript
instance.command.executeForceUpdate(options?: IForceUpdateOption)
```

## executeUndo

Feature: Undo
Expand Down Expand Up @@ -755,9 +765,11 @@ instance.command.executeWordTool()
```

## executeSetHTML

Feature: Set the editor HTML data

Usage:

```javascript
instance.command.executeSetHTML(payload: Partial<IEditorHTML)
```
Expand Down
10 changes: 10 additions & 0 deletions docs/guide/command-execute.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ instance.command.executeBackspace()
instance.command.executeSetRange(startIndex: number , endIndex: number)
```

## executeForceUpdate

功能:强制重新渲染文档

用法:

```javascript
instance.command.executeForceUpdate(options?: IForceUpdateOption)
```

## executeUndo

功能:撤销
Expand Down
2 changes: 2 additions & 0 deletions src/editor/core/command/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class Command {
public executeSelectAll: CommandAdapt['selectAll']
public executeBackspace: CommandAdapt['backspace']
public executeSetRange: CommandAdapt['setRange']
public executeForceUpdate: CommandAdapt['forceUpdate']
public executeUndo: CommandAdapt['undo']
public executeRedo: CommandAdapt['redo']
public executePainter: CommandAdapt['painter']
Expand Down Expand Up @@ -103,6 +104,7 @@ export class Command {
this.executeSelectAll = adapt.selectAll.bind(adapt)
this.executeBackspace = adapt.backspace.bind(adapt)
this.executeSetRange = adapt.setRange.bind(adapt)
this.executeForceUpdate = adapt.forceUpdate.bind(adapt)
// 撤销、重做、格式刷、清除格式
this.executeUndo = adapt.undo.bind(adapt)
this.executeRedo = adapt.redo.bind(adapt)
Expand Down
10 changes: 10 additions & 0 deletions src/editor/core/command/CommandAdapt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { DeepRequired } from '../../interface/Common'
import {
IAppendElementListOption,
IDrawImagePayload,
IForceUpdateOption,
IGetImageOption,
IGetValueOption,
IPainterOption
Expand Down Expand Up @@ -156,6 +157,15 @@ export class CommandAdapt {
})
}

public forceUpdate(options?: IForceUpdateOption) {
const { isSubmitHistory = false } = options || {}
this.range.clearRange()
this.draw.render({
isSubmitHistory,
isSetCursor: false
})
}

public undo() {
const isReadonly = this.draw.isReadonly()
if (isReadonly) return
Expand Down
4 changes: 4 additions & 0 deletions src/editor/interface/Draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export interface IDrawOption {
isSourceHistory?: boolean
}

export interface IForceUpdateOption {
isSubmitHistory?: boolean
}

export interface IDrawImagePayload {
width: number
height: number
Expand Down

0 comments on commit bc2f445

Please sign in to comment.