Skip to content

Commit

Permalink
fix:修复选中部分标题转为正文后,会有遗留的未选中的标题数据
Browse files Browse the repository at this point in the history
  • Loading branch information
luoluoTH committed Jan 7, 2025
1 parent 68888a0 commit d25b154
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ export const headingToParagraphCommand = $command(`headingToParagraphCommand`, (
return false // 没有选中任何内容
}
const parentNode = $from.node($from.depth)
if (parentNode.type.name === state.schema.nodes.heading.name) {
if (parentNode && parentNode.type.name === state.schema.nodes.heading.name) {
let textNode = state.schema.text(parentNode.textContent)
// 创建新的节点,并用它替换列表项
const node = state.schema.nodes.paragraph.create(
null,
textNode // 使用列表项的内容填充
)

const start = $from.start() // 标题节点的起始位置
const end = $from.end() // 标题节点的结束位置
// 替换整个标题节点
const tr = state.tr.replaceRangeWith(from, to, node)

if (dispatch) dispatch(tr)

const transaction = state.tr.replaceRangeWith(start, end, node)
if (dispatch) dispatch(transaction)
return true
}
return false
Expand Down

0 comments on commit d25b154

Please sign in to comment.