diff --git a/src/menus/indent/operate-element.ts b/src/menus/indent/operate-element.ts index 5959a8dad..75858a871 100644 --- a/src/menus/indent/operate-element.ts +++ b/src/menus/indent/operate-element.ts @@ -42,7 +42,7 @@ function parseIndentation(editor: Editor): IndentationOptions { function operateElement($node: DomElement, type: String, editor: Editor): void { const $elem = $node.getNodeTop(editor) - const reg = /^P$/i + const reg = /^(P|H[0-9]*)$/ if (reg.test($elem.getNodeName())) { if (type === 'increase') increaseIndentStyle($elem, parseIndentation(editor)) diff --git a/test/unit/menus/indent.test.ts b/test/unit/menus/indent.test.ts index 0402e9cde..f29be2d24 100644 --- a/test/unit/menus/indent.test.ts +++ b/test/unit/menus/indent.test.ts @@ -31,7 +31,7 @@ test('indent 菜单:增加缩进', () => { editor.selection.createRangeByElem($h, true, true) indentMenu.command('increase') - expect($h.elems[0].style['paddingLeft']).toBe('') + expect($h.elems[0].style['paddingLeft']).toBe('2em') editor.selection.createRangeByElem($p, true, true) indentMenu.command('increase') @@ -42,6 +42,10 @@ test('indent 菜单:减少缩进', () => { editor.selection.createRangeByElem($p, false, true) indentMenu.command('decrease') expect($p.elems[0].style['paddingLeft']).toBe('') + + editor.selection.createRangeByElem($h, false, true) + indentMenu.command('decrease') + expect($h.elems[0].style['paddingLeft']).toBe('') }) test('indent 菜单:叠加缩进', () => { @@ -49,4 +53,9 @@ test('indent 菜单:叠加缩进', () => { indentMenu.command('increase') indentMenu.command('increase') expect($p.elems[0].style['paddingLeft']).toBe('4em') + + editor.selection.createRangeByElem($h, true, true) + indentMenu.command('increase') + indentMenu.command('increase') + expect($h.elems[0].style['paddingLeft']).toBe('4em') })