Skip to content

Commit

Permalink
fix: indent 缩进时, 增加对 head 的处理
Browse files Browse the repository at this point in the history
  • Loading branch information
lichenabson committed May 17, 2021
1 parent 745fa10 commit 8d506e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/menus/indent/operate-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
11 changes: 10 additions & 1 deletion test/unit/menus/indent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -42,11 +42,20 @@ 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 菜单:叠加缩进', () => {
editor.selection.createRangeByElem($p, true, true)
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')
})

0 comments on commit 8d506e4

Please sign in to comment.