I'm trying to build a word processor web app, similar to Google Docs. I've started using Mercury Editor (which relies on the contentEditable attribute) and I've created an editable div element that looks like a paper page (as Google Docs does).
Now the big problem is how to deal with several pages, i.e., how to detect when text (or other content) overflows the page height and then create a new page with the content split. There are a few scenarios when this could ocurr:
- A user type a break line at the end of the page. A new page should be created.
- A user is typing a word and he reaches the end of the page. A new page should be created and that word should be moved to the new page.
- A user pastes some large text and it doesn't fit totally on the current page. A new page should be created and only the text that doesn't fit should be moved to the new one.
- A user inserts any other element (an image for instance), that doesn't fit in the current page. A new page should be created with that element.
I've tried to dive into the Google Docs JS code but it's pretty impossible to follow, since it's compressed. There is a standalone version of Google Docs, with the code beautified, however it's old and doesn't handle several pages.
Any hint about how to accomplish this will be appreciated.