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
136 stars 59 forks source link

Added click listener to get current applied format. #30

Open Rushang08 opened 1 year ago

Rushang08 commented 1 year ago

Problem: Issue Link

Soluation: We have added the click listener which will send all applied format for current tag.

PFA:

https://github.com/Andrew-Chen-Wang/RichEditorView/assets/8275040/c1e592d6-7c5f-4724-b39f-0c5b848f5c28

This enhancement is particularly beneficial, as it introduces an event that empowers users to effortlessly retrieve an array of applied formats. By capturing content changes through our delegate method and manually invoking the click event, users gain streamlined access to a comprehensive array of string-based formats that have been applied

Example Code:

extension TestViewController: RichEditorDelegate {

    func richEditor(_ editor: RichEditorView, handle action: String) {

        let commaSeparatedString = action
        let arrayOfStrings = commaSeparatedString.split(separator: ",").map { String($0) }

        buttonStateChange(
            isSelected: arrayOfStrings.contains("unorderedList") ? true : false,
            format: .bulletPoint
        )

    }

   func richEditor(_ editor: RichEditorView, contentDidChange content: String) {

       editor.runJS("document.querySelector('body').click();")

        if content.count > 40000 {
            editor.html = prevText
        } else {
            prevText = content
        }

    }

}