diff --git a/editors/demo/src/OEN/OEN.js b/editors/demo/src/OEN/OEN.js index 2f3cb244fd8789a122a21247fae80befb889045e..2a994776548e693ea31c79172ba6b82d0d095b32 100644 --- a/editors/demo/src/OEN/OEN.js +++ b/editors/demo/src/OEN/OEN.js @@ -26,7 +26,7 @@ const user = { }; const val = `<h3>33333</h3><section class="section"><div class="introduction" data-type="content_structure_element"><p>Intro</p></div> - <div class="outline" data-type="content_structure_element"><p>outline</p></div></section> + <div class="outline" data-type="content_structure_element"><h1>heading when i click note</h1><p>some text when i click note</p></div></section> <section class="section"><div class="introduction" data-type="content_structure_element"><p>Intro</p></div> <div class="outline" data-type="content_structure_element"><p>outline</p></div></section>`; diff --git a/wax-prosemirror-services/src/OENContainersService/PopulateHeadingsComponent.js b/wax-prosemirror-services/src/OENContainersService/PopulateHeadingsComponent.js index c7d9394c5d212189b28bd8173b4beb457591a07c..4968f1eefe54a95457d3cbd80aa7d273d82ab809 100644 --- a/wax-prosemirror-services/src/OENContainersService/PopulateHeadingsComponent.js +++ b/wax-prosemirror-services/src/OENContainersService/PopulateHeadingsComponent.js @@ -78,20 +78,35 @@ export default ({ setPosition, position }) => { selection: { from, to }, doc, } = main.state; - const parser = DOMParser.fromSchema(main.state.config.schema); - const allSections = []; + const allSectionNodes = []; doc.descendants((editorNode, index) => { if (editorNode.type.name === 'oen_section') { - allSections.push(editorNode); + allSectionNodes.push(editorNode); + } + }); + + let sectionNode; + let sectionNodePosition; + + main.state.doc.nodesBetween(from, to, (node, pos) => { + if (node.type.name === 'oen_container') { + sectionNode = node; + sectionNodePosition = pos; } }); - const content = - '<h1>heading when i click note</h1><p>some text when i click note</p>'; + let content = ''; + + const parser = DOMParser.fromSchema(main.state.config.schema); const parsedContent = parser.parse(elementFromString(content)); - tr.replaceWith(from - 1, to - 1, parsedContent); + + tr.replaceWith( + sectionNodePosition + 1, + sectionNodePosition + sectionNode.content.size, + parsedContent, + ); selectionToInsertionEnd(tr, tr.steps.length - 1, -1); main.dispatch(tr); };