I have been working on the creation of a specialized text editor running in the browser. I've got a question that has put me in a stupor. How to detect and divide long text into separate pages, as is done in Google docs? I know that google docs does not work through contenteditable, but there must be some solution...
Edit1: We need to consider a few scenarios:
- We load a document by means of json object and then rendering our pages.
- We are typing the text and reached the end of the page.
- We delete the text.
- We insert or remove a piece of text.
https://googleblog.blogspot.ru/2011/04/pagination-comes-to-google-docs.html
page.html
<div class="box-base">
<div id="page-1" class="page">
<div id="editable-1" class="document" contenteditable="true"></div>
</div>
<div id="page-2" class="page">
<div id="editable-2" class="document" contenteditable="true"></div>
</div>
</div>
styles.css
.box-base {
margin-left: 50px;
flex: 1 0 430px;
border-style: solid;
display: -webkit-flex;
display: flex;
flex-wrap: wrap;
justify-content: center;
height: 900px;
overflow: auto;
}
.page {
width: @page-width;
height: @page-width * 1.414;
/*overflow-y: auto;*/
background: white;
margin: 25px 0 25px 0;
}
.document {
/*max-height: 1000px;*/
overflow: hidden;
}
I think you have to try splitting the text at different places and watch until scrollHeight is just less than or equal to clientHeight. Something like: