SCEditor icon indicating copy to clipboard operation
SCEditor copied to clipboard

Android, Chrome, line break does not move cursor to new line

Open alekseyderyugin opened this issue 4 years ago • 3 comments

Android 9 chrome 88.0.4324.93 with gboard Android 10 chrome 87.0.4280.101 with gboard

If iframe contains

<p>
  <font color="#1e92f7">some text</font>
</p>

or

<p>
   <b>some text</b>
</p>

line break (enter) not move cursor to new line.

Demo from https://issuetracker.google.com/issues/177757645: https://drive.google.com/file/d/15sVf_TrDo1WRAU1fFrR8YnuTVUbSAjFU/view

If <p> replace to <div> - cursor move, its ok.

This is not an editor problem, this is a chrome problem. But it needs to be solved somehow.

Why this is a chrome problem...

Run next code on android device with gboard. Place cursor at end of line and touch 'enter'.

<style>
    .container {
        height: 250px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
</style>

<div class="container">
    <iframe id="ifrm" frameborder="1"></iframe>
</div>

<script type="text/template" id="iframeContent">
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Inner</title>
    </head>
    <body contenteditable="true">
    <p><font color="#7fdbff">Yhhhhjh</font></p>
    </body>
    </html>
</script>

<script>
    var iframe = document.getElementById( 'ifrm' );
    var content = document.getElementById("iframeContent").innerHTML;
    var frameDoc = iframe.document;
    if (iframe.contentWindow)
        frameDoc = iframe.contentWindow.document;

    frameDoc.open();
    frameDoc.writeln(content);
    frameDoc.close();
</script>

I found next links: https://github.com/quilljs/quill/issues/3240 https://issuetracker.google.com/issues/177757645 (issue from quill developer)

I can replace <p> with <div> but i not shure that it not break something. Also, I'm not sure that I can guarantee that <p> wont never be inserted in iframe content.

This is an annoying problem. How can I solve it?

alekseyderyugin avatar Apr 23 '21 10:04 alekseyderyugin

Thanks for reporting, that is a very annoying bug.

I can replace <p> with <div> but i not shure that it not break something. Also, I'm not sure that I can guarantee that <p> wont never be inserted in iframe content.

That shouldn't break anything. You would need to modify the editor, to replace all <p> tags as it auto inserts some <p> tags if there aren't any in the body and also to add a newline after a block element.

samclarke avatar Apr 25 '21 18:04 samclarke

Thanks for your reply!

I created the list of places, where <p> should be replace with<div> in jquery.sceditor.bbcode.js, version 3.0.0:

  1. var _templates = { .. html: 1748
  2. base.insertHTML 3160
  3. base.selectedHtml 3359
  4. function wrapInlines 3989
  5. autofocus = function () { 4916
  6. base.setWysiwygEditorValue 5985
  7. appendNewLine = function () { 6447
  8. base.clearBlockFormatting 7267

This list is correct?

alekseyderyugin avatar Apr 26 '21 06:04 alekseyderyugin

That looks correct to me.

samclarke avatar Apr 29 '21 14:04 samclarke