Reputation: 33
I am building a WYSIWYG editor for an web application which will simulate a "MS Word feel", that is, with the content being directly put inside a contenteditable element.
After much research, I was finally able to somehow "fake" a pagebreak between pages using a div element inside the contenteditable, built with two other float elements: (i) an element to push down the actual pagebreaker, such as a pseudo element would [the pagebreak-push]; and (ii) the pagebreak itself [the pagebreak-main]. The float pagebreak enables me to type text within the contenteditable in a way that the text will wrap around the pagebreak. Since the pagebreak is 100% width, text should only skip it.
This is what I got so far (JSFiddle: https://jsfiddle.net/OctavioSI/c19w68ff/10/):
HTML
<div class="wysiwyg-canvas">
<div class="wysiwyg-content" contenteditable="true">
Sample Text
<div class="pagebreak" contenteditable="false">
<span class="pagebreak-push"></span>
<span class="pagebreak-main" contenteditable="false">Pagebreak</span>
</div>
</div>
<div class="background-pages">
<div class="wysiwyg-page"></div>
<div class="wysiwyg-page pagespace"></div>
</div>
</div>
CSS
.wysiwyg-canvas{
background-color: #999999;
border:1px solid #cccccc;
padding:0.7vw;
overflow-y: auto;
height:400px;
width:100%;
position:relative;
font-size:1em;
}
.wysiwyg-page{
background-color: #FFFFFF;
border:1px solid #000000;
padding:0;
overflow: hidden;
cursor:text;
height:200px;
}
.wysiwyg-page.pagespace{
margin-top:5px;
}
.wysiwyg-content{
position:absolute;
top:5px;
left:5px;
width:calc(100% - 10px);
padding:0;
-moz-user-select: all;
-khtml-user-select: all;
-webkit-user-select: all;
user-select: all;
font-size:1em;
font-family: Verdana;
font-weight: normal;
color:#000000;
text-transform: none;
line-height:1em;
display:block;
border:1px solid green;
}
.pagebreak > .pagebreak-push{
float: right;
height:155px;
border:0;
width:1px;
display:block;
border-right:1px solid brown; /* Used for better view while testing */
}
.pagebreak > .pagebreak-main {
float:right;
clear:both;
width:100%;
height:50px;
margin: 0;
border:1px solid #aaaaaa; /* Used for better view while testing */
background-color:#cccccc;
line-height:50px;
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
display:block;
}
.pagebreak {
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
display:block;
padding:0;
margin:0;
text-align:center;
color:#aaaaaa;
}
div:focus,
div:active,
div:hover {
text-decoration:none;
outline:none;
}
The Problem: The code itself works fine to a certain extent, as you can see in the JSFiddle and in the following screenshot (situation 1). Nonetheless, if I put the caret in the first position after the pagebreak and start typing, the text ends up being put inside the pagebreak space (in a vertical line, almost as if being put before the pagebreak) (situation 2). - Screenshot: Wrong behaviour after the pagebreak
My question is: is there any way to avoid this strange behaviour, thus making the text correctly skip the pagebreak without this glitch?
Some additional thoughts / info:
Thanks in advance.
Upvotes: 3
Views: 2242
Reputation: 46
Try:
.wysiwyg-content div {
word-wrap: normal;
}
According to the link you provided, apparently they tweaked some functionalities of line wrapping with float 100% in the newest version of chrome. So maybe forcing the word wrapping to be normal might fix the problem.
Upvotes: 3