Skip to content

Commit

Permalink
fix: 回车切换字号失效
Browse files Browse the repository at this point in the history
  • Loading branch information
blackhu0804 committed Mar 31, 2021
1 parent 5ad1ff4 commit 5969bba
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/menus/font-size/index.ts
Expand Up @@ -39,19 +39,21 @@ class FontSize extends DropListMenu implements MenuActive {
const editor = this.editor
const isEmptySelection = editor.selection.isSelectionEmpty()

const $selectionElem = editor.selection.getSelectionContainerElem()?.elems[0]
let selectionElem = editor.selection.getSelectionContainerElem()?.elems[0]

if ($selectionElem == null) return
if (selectionElem == null) return

const isFont = $selectionElem?.nodeName.toLowerCase() !== 'p'
const isSameSize = $selectionElem?.getAttribute('size') === value
const isFont = selectionElem?.nodeName.toLowerCase() !== 'p'
const isSameSize = selectionElem?.getAttribute('size') === value
if (isEmptySelection) {
if (isFont && !isSameSize) {
const $elems = editor.selection.getSelectionRangeTopNodes()
const focusElem = $elems[0].elems[0]
editor.selection.createRangeByElem($elems[0])
editor.selection.moveCursor($elems[0].elems[0])
editor.selection.moveCursor(focusElem)
selectionElem = focusElem
}
editor.selection.setRangeToContainerElem($selectionElem)
editor.selection.setRangeToContainerElem(selectionElem)
// 插入空白选区
editor.selection.createEmptyRange()
}
Expand Down

0 comments on commit 5969bba

Please sign in to comment.