SCEditor icon indicating copy to clipboard operation
SCEditor copied to clipboard

Feature Request: enterMode option

Open martec opened this issue 9 years ago • 22 comments

@samclarke If you could put it in priority. Many in Mybb are complaining about this differentiated behavior that has in SCEditor using Chrome. http://community.mybb.com/thread-159045.html

Something this that has in CKEditor : http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-enterMode

To avoid something this: https://github.com/samclarke/SCEditor/issues/181#issuecomment-57037618

Only SCEditor result in something above using Chrome... makes no sense, just SCEditor act differently. I tried Redactor, CKEditor, WysiBB etc... and not result in something above.

martec avatar Nov 03 '14 00:11 martec

@samclarke plz check this. To avoid create same tag when press enter. https://github.com/samclarke/SCEditor/issues/181#issuecomment-57037618

martec avatar Mar 16 '15 03:03 martec

Personally, as it works now, it seems both are correct ways of expressing the content. Is that wrong? Did I understand wrong what you are trying to show?

brunoais avatar Mar 16 '15 08:03 brunoais

@brunoais what logic to put same tag in all line? make sense?

https://github.com/samclarke/SCEditor/issues/181#issuecomment-57106654

martec avatar Mar 16 '15 09:03 martec

Yes. <i> is inline Element. Enter is to make a new block element (no matter what the browser actually places) Inline elements must not span through multiple block elements. Changing that is not viable at all :S. Use ctrl+Enter to make a new line.

What can be made, however, is to internally remap Enter to ctrl+Enter. Do you want that?

brunoais avatar Mar 16 '15 09:03 brunoais

@brunoais you tried other editor? for me not made any sense. Only polute message. And it is not easy to convince all users to press ctrl + enter. This is inconvenience.

martec avatar Mar 16 '15 09:03 martec

you tried other editor?

CKE? Yeah. It is very memory heavy, a bit too slow, at times with loads of code bloat. It is also a huge pain that all buttons are disabled when in source code mode.

Also, you didn't answer my question.

brunoais avatar Mar 16 '15 10:03 brunoais

@brunoais my request of this ticket is "Feature Request: enterMode option" but remap Enter to ctrl+enter is ok for me...

martec avatar Mar 16 '15 10:03 martec

@brunoais i'm too i hate cke... but mybb team want change to CKE in mybb 2.0 http://community.mybb.com/thread-168414.html for me is very bad idea... but i can't made anything.

martec avatar Mar 16 '15 10:03 martec

There, I placed there a good question for them to think on. AFAIK, there's no better alternative to SCE. It has its own issues, yes, but that doesn't mean it is not the best one for this purpose.

brunoais avatar Mar 16 '15 12:03 brunoais

How do I remap Enter to Ctrl+Enter?

MadSpindel avatar Mar 22 '15 14:03 MadSpindel

There's currently no such thing... Probably making a shortcut using addShortcut() may work.

brunoais avatar Mar 24 '15 16:03 brunoais

@brunoais Nice suggestion! I tried it. It kinda works, but I have a problem.

I use:

this.wysiwygEditorInsertHtml('<br>');

to insert newlines. But somehow when you are typing som text and press enter, nothing happens. You need to use "enter" twice for newline.

But, if there is no text it works as expected. Only need one "enter". Any idea why?

MadSpindel avatar Mar 24 '15 19:03 MadSpindel

Not really, no. Try checking how the HTML changes as you type. That may help.

brunoais avatar Mar 24 '15 21:03 brunoais

I tried it in Firefox and IE11 now. No problem at all. It looks like it is something related to Chrome/Webkit.

MadSpindel avatar Mar 24 '15 21:03 MadSpindel

chrome-linebreak-bug

MadSpindel avatar Mar 24 '15 21:03 MadSpindel

Where can I find the code for "shift+enter"?

MadSpindel avatar Mar 25 '15 19:03 MadSpindel

After some digging I found #248 Somehow I need to reuse some of this logic but do not know how... Any can help?

MadSpindel avatar Mar 25 '15 19:03 MadSpindel

If the <br> is the last child of a block and the previous sibling is inline, then the <br> will be collapsed in all browsers except from IE < 11. In order for the new line to show there needs to be two <br> elements.

The code to do this is already in the editor so adding an option to enable it for all blocks shouldn't be too difficult.

This is the code that's currently used in the editor to do it is this:

instance.addShortcut('enter', function () {
    var currentNode = this.currentBlockNode();
    var rangeHelper = this.getRangeHelper();

    // Browsers have special handling for list items so exclude them
    if ($(currentNode).is('li') || $(currentNode.parent).is('li')) {
        return;
    }

    var br = this.getBody()[0].ownerDocument.createElement('br');
    rangeHelper.insertNode(br);

    // The last <br> of a block will be collapsed if the previous sibling
    // is inline (except in IE < 11) so need to make sure the <br> that
    // was inserted isn't the last child of a block.
    if (!$.sceditor.ie || $.sceditor.ie > 10) {
        var parent    = br.parentNode;
        var lastChild = parent.lastChild;

        // Sometimes an empty next node is created after the <br>
        if (lastChild && lastChild.nodeType === 3 && lastChild.nodeValue === '') {
            parent.removeChild(lastChild);
            lastChild = parent.lastChild;
        }

        if (lastChild === br && !$.sceditor.dom.isInline(parent, true) &&
                $.sceditor.dom.isInline(br.previousSibling)) {
            rangeHelper.insertHTML('<br>');
        }
    }

    return false;
});

samclarke avatar Mar 25 '15 20:03 samclarke

problem that in chrome when press enter key create another 'div' blocks. In FF is correct, use same 'div' block.

so ie is not consistent.

sceditor in FF using something like: CKEDITOR.ENTER_BR (2) – lines are broken with 'br' elements;

but in chrome (webkit) using something like: CKEDITOR.ENTER_DIV (3) – new 'div' blocks are created.

What i want, i want that set CKEDITOR.ENTER_BR (2) to all brownser.

http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-enterMode

martec avatar Mar 26 '15 10:03 martec

You're right, it should really have consistent behaviour. I'm just not sure which, if any, should be the default.

Maybe the best solution is to have an option like CKEditor so you can choose between the default browser behaviour, newlines or blocks. It shouldn't be too difficult implement or increase the code size as the code to do it's already there.

samclarke avatar Mar 26 '15 18:03 samclarke

@samclarke thanks! Options is better...

martec avatar Mar 27 '15 01:03 martec

+1

Eldenroot avatar Sep 11 '17 14:09 Eldenroot