Commit 5d537563 authored by Яков's avatar Яков
Browse files

update fix issue

parent dce5c6ec
{ {
"name": "react-ag-qeditor", "name": "react-ag-qeditor",
"version": "1.1.74", "version": "1.1.75",
"description": "WYSIWYG html editor", "description": "WYSIWYG html editor",
"author": "atma", "author": "atma",
"license": "MIT", "license": "MIT",
......
...@@ -210,10 +210,50 @@ const ToggleBlock = Node.create({ ...@@ -210,10 +210,50 @@ const ToggleBlock = Node.create({
return additionalOffset > 0 ? tr : null return additionalOffset > 0 ? tr : null
} }
const cleanLeadingEmptyParagraphs = (state) => {
const doc = state.doc
const tr = state.tr
let offset = 0
doc.forEach((node, pos) => {
if (node.type.name !== 'toggleBlock') return
// Считаем сколько пустых параграфов стоят первыми подряд
let emptyCount = 0
for (let i = 0; i < node.childCount; i++) {
const child = node.child(i)
if (child.type.name === 'paragraph' && child.childCount === 0) {
emptyCount++
} else {
break
}
}
// Оставляем хотя бы один блок — удаляем только если после пустых есть что-то ещё
const removable = node.childCount > emptyCount ? emptyCount : Math.max(0, emptyCount - 1)
if (removable === 0) return
// Удаляем removable пустых параграфов с начала содержимого toggle-блока
const contentStart = pos + offset + 1 // +1 = открывающий токен toggle-блока
let deleteEnd = contentStart
for (let i = 0; i < removable; i++) {
deleteEnd += node.child(i).nodeSize
}
tr.delete(contentStart, deleteEnd)
offset -= (deleteEnd - contentStart)
})
return tr.steps.length > 0 ? tr : null
}
return [ return [
new Plugin({ new Plugin({
key: new PluginKey('toggleBlockGap'), key: new PluginKey('toggleBlockGap'),
view (editorView) { view (editorView) {
// Миграция: убираем пустые параграфы в начале toggle-блоков (артефакт старого бага)
const cleanTr = cleanLeadingEmptyParagraphs(editorView.state)
if (cleanTr) editorView.dispatch(cleanTr)
// Fix adjacent toggle blocks present in initially loaded content // Fix adjacent toggle blocks present in initially loaded content
const tr = buildGapFix(editorView.state) const tr = buildGapFix(editorView.state)
if (tr) editorView.dispatch(tr) if (tr) editorView.dispatch(tr)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment