RichEditorView icon indicating copy to clipboard operation
RichEditorView copied to clipboard

How to get attributed string (Highlight)

Open user723 opened this issue 3 years ago • 10 comments

I can get the string with editorView.getSelectedText, but how can I get attributed string( if it's bold, italic, etc.) ?

user723 avatar May 10 '21 17:05 user723

Does getSelectedHref work?

Andrew-Chen-Wang avatar May 10 '21 18:05 Andrew-Chen-Wang

I don't use any url in my project, that's why I didnt check.

user723 avatar May 11 '21 09:05 user723

I checked it now , getSelectedHref works

user723 avatar May 11 '21 10:05 user723

But how can I get attributed string?

user723 avatar May 11 '21 10:05 user723

I can get String and URL, but I cannot get attributed string!?

user723 avatar May 11 '21 10:05 user723

Ah that's... strange. Typically you can just convert your string to an attributed string like NSAttributedString(string: string)

Andrew-Chen-Wang avatar May 11 '21 10:05 Andrew-Chen-Wang

In your example : editorView.html = "What I'll usually do for focus and unfocus is similar to what Google Docs does. The insert link functionality is similar to Reddit's except I use a UIAlertController. There are some added and altered functionality like running your custom JS; you will just have to learn what goes on with this package, but it's a quick learn. Good luck! If you have any issues, Yoom will help out, so long as those issues are opened in this repo. Credits still go out to cjwirth and C. Bess"

"Good luck!" is bold. When I use getSelectedText, I get the text as String, but I want to get attributed string, then I can know selected text is bold, italic, underline and/or etc.

user723 avatar May 11 '21 10:05 user723

Did you try using NSAttributedString(string: editorView.getSelectedHref())?

I'll check on it. Gimme a sec. Edit: ok so it looks like the method is just half-ass broken. I'll probably find some code to replace it from somewhere like TinyMCE.

Andrew-Chen-Wang avatar May 11 '21 10:05 Andrew-Chen-Wang

Thanks.

If you add this function like this, when the user selected some text or moved the cursor to a different position can get attributed string.

  • func editor(_ editor: TextEditorView, selectedTextAttributeDidChange attribute: TextAttribute)

You can check this link (https://github.com/OneupNetwork/SQRichTextEditor).

user723 avatar May 11 '21 11:05 user723

It's definitely possible, but to make this fix actually work, there's a bit of discussion that I'd have to read over since there's multiple ways "getSelectedHref" can work: https://github.com/cjwirth/RichEditorView/pull/25

Andrew-Chen-Wang avatar May 11 '21 11:05 Andrew-Chen-Wang