UNPKG

wangeditor

Version:

wangEditor - 轻量级 web 富文本编辑器,配置方便,使用简单,开源免费

54 lines (45 loc) 1.39 kB
/** * @description 重做 * @author tonghan */ import $ from '../../utils/dom-core' import Editor from '../../editor/index' import BtnMenu from '../menu-constructors/BtnMenu' import { MenuActive } from '../menu-constructors/Menu' class Redo extends BtnMenu implements MenuActive { constructor(editor: Editor) { const $elem = $( `<div class="w-e-menu" data-title="恢复"> <i class="w-e-icon-redo"></i> </div>` ) super($elem, editor) } /** * 点击事件 */ public clickHandler(): void { const editor = this.editor editor.history.restore() // 重新创建 range,是处理当初始化编辑器,API插入内容后撤销,range 不在编辑器内部的问题 const children = editor.$textElem.children() if (!children?.length) return const $last = children.last() editor.selection.createRangeByElem($last, false, true) editor.selection.restoreSelection() } /** * 尝试修改菜单激活状态 */ public tryChangeActive(): void { // 标准模式下才进行操作 if (!this.editor.isCompatibleMode) { if (this.editor.history.size[1]) { this.active() } else { this.unActive() } } } } export default Redo