/** * @description 标题 * @author wangfupeng */ import DropListMenu from '../menu-constructors/DropListMenu' import $ from '../../utils/dom-core' import Editor from '../../editor/index' import { MenuActive } from '../menu-constructors/Menu' class Head extends DropListMenu implements MenuActive { constructor(editor: Editor) { const $elem = $('
') const dropListConf = { width: 100, title: '设置标题', type: 'list', // droplist 以列表形式展示 list: [ { $elem: $('${editor.i18next.t('menus.dropListMenu.head.正文')}
`), value: '', }, ], clickHandler: (value: string) => { // 注意 this 是指向当前的 Head 对象 this.command(value) }, } super($elem, editor, dropListConf) } /** * 执行命令 * @param value value */ public command(value: string): void { const editor = this.editor const $selectionElem = editor.selection.getSelectionContainerElem() if ($selectionElem && editor.$textElem.equal($selectionElem)) { // 不能选中多行来设置标题,否则会出现问题 // 例如选中的是
xxx
yyy
来设置标题,设置之后会成为