Skip to content

Commit

Permalink
ReplaceSelectedContent PoC
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn committed Apr 29, 2024
1 parent fec1e9d commit ed0cdfc
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions OneMore/Models/PageEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,5 +497,33 @@ private void CleanupOrphanedElements()
Anchor = page.EnsureContentContainer(false);
}
}


public async Task<bool> ReplaceSelectedContent(XElement replacement)
{
var content = await ExtractSelectedContent();

if (!content.HasElements)
{
// no selection region found
return false;
}

if (replacement.Name.LocalName != "OE")
{
replacement = new XElement(ns + "OE", replacement);
}

if (Anchor.Name.LocalName.In("OE", "HTMLBlock"))
{
Anchor.AddAfterSelf(replacement);
}
else
{
Anchor.AddFirst(replacement);
}

return true;
}
}
}

0 comments on commit ed0cdfc

Please sign in to comment.