Andrew-Chen-Wang / RichEditorView

Rich Text Editor in Swift. Newly Featured Code and Swift 5 compatible of cjwirth/RichEditorView.
BSD 3-Clause "New" or "Revised" License
134 stars 59 forks source link

Toggling Header Styles #11

Closed KAUSHIKTECHIE closed 3 years ago

KAUSHIKTECHIE commented 4 years ago

How can we make the headers to toggle like the bold,italics meaning how to remove heading when clicked for second time. The header/size buttons should also be a toggle; doesn’t allow to toggle back to default size.

markosrx commented 3 years ago

+1

Andrew-Chen-Wang commented 3 years ago

Hopefully this helps!:

RE.setHeading = function(heading) {
    var sel = document.getSelection().getRangeAt(0).startContainer.parentNode;
    document.execCommand('formatBlock', false, sel.tagName === `H${heading}` ? '<p>' : `<h${heading}>`);
};

Note to self: document.execCommand is deprecated, but there's literally no alternative... we'll have to see what happens after finals.

Other notes for future me The sister repo also doesn't seem to have a solution unfortunately... https://github.com/wasabeef/richeditor-android/blob/ce152b910a59c66863baa68b007ac67e6b9de671/richeditor/src/main/assets/rich_editor.js#L155-L157
Andrew-Chen-Wang commented 3 years ago

Any ideas where else I can add this besides the heading?

Andrew-Chen-Wang commented 3 years ago

Fixed in ed734f6f9bb2bb2e09efe183764b488d50d3bcf1