Skip to content

Conversation

@Rushang08
Copy link

@Rushang08 Rushang08 commented Aug 31, 2023

Problem: Issue Link

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

PFA:

Simulator.Screen.Recording.-.iPhone.14.Pro.-.2023-08-31.at.16.16.39.mp4

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
		}
             
	}
        
}

We already have custom delegate method where we can send custom handle and this method will be decieder for us to check already applied format and we can play with selected and unselected method
- We have content change delegate method and we can now manually call the click event if any content change and we can get the all latest format.  

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

- This will also take care if user click anywhere in DIV.
Copy link
Owner

@Andrew-Chen-Wang Andrew-Chen-Wang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this, but this seems a bit jacky and not robust for the future in terms of deprecated methods and method of updating ourselves.

// You can replace this code with any action you want to perform when a click happens.
var items = [];

if (document.queryCommandState('bold')) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is very repetitive. Query command state is also deprecated and may not work if you load in HTML with certain formats already applied

Comment on lines +76 to +77
const allAppliedFormat = items.toString()
RE.callback(allAppliedFormat)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't ideal. A parsable list would be better or performing the callback one at a time since you're not getting the formats in the order of encapsulation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants