文档历史记录模块

历史记录模块

History 模块负责处理 Quill 的撤销和重做操作。它可以配置以下选项:

¥The History module is responsible for handling undo and redo for Quill. It can be configured with the following options:

配置

¥Configuration

delay

  • 默认值:1000

    ¥Default: 1000

delay 毫秒内发生的更改将合并为单个更改。

¥Changes occuring within the delay number of milliseconds are merged into a single change.

例如,将延迟设置为 0,几乎每个字符都会被记录为一次更改,因此撤消操作会一次撤消一个字符。将延迟设置为 1000 时,撤消将撤消过去 1000 毫秒内发生的所有更改。

¥For example, with delay set to 0, nearly every character is recorded as one change and so undo would undo one character at a time. With delay set to 1000, undo would undo all changes that occured within the last 1000 milliseconds.

maxStack

  • 默认值:100

    ¥Default: 100

历史记录的撤消/重做堆栈的最大大小。使用 delay 选项的合并更改计为单个更改。

¥Maximum size of the history's undo/redo stack. Merged changes with the delay option counts as a singular change.

userOnly

  • 默认值:false

    ¥Default: false

默认情况下,所有更改(无论是源自用户输入还是通过 API 以编程方式进行)都被视为相同,并且可以通过历史记录模块撤消或重做更改。如果 userOnly 设置为 true,则只有用户更改会被撤消或重做。

¥By default all changes, whether originating from user input or programmatically through the API, are treated the same and change be undone or redone by the history module. If userOnly is set to true, only user changes will be undone or redone.

示例

¥Example

const quill = new Quill('#editor', {
modules: {
history: {
delay: 2000,
maxStack: 500,
userOnly: true
},
},
theme: 'snow'
});

API

clear

清除历史记录堆栈。

¥Clears the history stack.

方法

¥Methods

clear()

示例

¥Examples

quill.history.clear();

cutoff

通常,短时间内进行的更改(由 delay 配置)会合并为单个更改,因此触发撤消操作将撤消多个更改。使用 cutoff() 将重置合并窗口,这样调用 cutoff() 之前和之后的更改将不会被合并。

¥Normally changes made in short succession (configured by delay) are merged as a single change, so that triggering an undo will undo multiple changes. Using cutoff() will reset the merger window so that a changes before and after cutoff() is called will not be merged.

方法

¥Methods

cutoff()

示例

¥Examples

quill.history.cutoff();

undo

撤消上次更改。

¥Undo last change.

方法

¥Methods

undo()

示例

¥Examples

quill.history.undo();

redo

如果上次更改是撤消,则重做本次撤消。否则不执行任何操作。

¥If last change was an undo, redo this undo. Otherwise does nothing.

方法

¥Methods

redo()

示例

¥Examples

quill.history.redo();