Skip to content
Snippets Groups Projects
Commit 5f063550 authored by chris's avatar chris
Browse files

select nodes content

parent 43e7e2be
No related branches found
No related tags found
1 merge request!407Hhmi fixes
...@@ -26,7 +26,7 @@ const user = { ...@@ -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> 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> <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"><p>outline</p></div></section>`;
......
...@@ -78,20 +78,35 @@ export default ({ setPosition, position }) => { ...@@ -78,20 +78,35 @@ export default ({ setPosition, position }) => {
selection: { from, to }, selection: { from, to },
doc, doc,
} = main.state; } = main.state;
const parser = DOMParser.fromSchema(main.state.config.schema);
const allSections = []; const allSectionNodes = [];
doc.descendants((editorNode, index) => { doc.descendants((editorNode, index) => {
if (editorNode.type.name === 'oen_section') { 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 = let content = '';
'<h1>heading when i click note</h1><p>some text when i click note</p>';
const parser = DOMParser.fromSchema(main.state.config.schema);
const parsedContent = parser.parse(elementFromString(content)); 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); selectionToInsertionEnd(tr, tr.steps.length - 1, -1);
main.dispatch(tr); main.dispatch(tr);
}; };
......
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