linkedin / Hakawai

A powerful, extensible UITextView.
Apache License 2.0
782 stars 104 forks source link

Khmer (Cambodian) Language tagging issue #232

Closed purva-dev closed 3 years ago

purva-dev commented 3 years ago

I'm facing issue in adding the mention attribute of khmer language text. i.e not able to create a tag for khmer language always returns nil

Screenshot 2021-03-24 at 5 31 00 PM

Screenshot 2021-03-24 at 5 31 33 PM

bkoatz commented 3 years ago

we have not tested with khmer before as it's not supported on LI. we can try and look through what the issue is, but encourage you to look around as well!

purva-dev commented 3 years ago

@bkoatz Hello!! Thanks for your reply and now I would like to add here that we figured out the issue is where the string which we are sending in length to create NSRange is type of String

let myNSRange = NSRange(location: aStartIndex, length: aStrName.count)

so we just have to convert the String type to NSString like this

let myNSRange = NSRange(location: aStartIndex, length: (aStrName as NSString).length)

by this we can get the proper length of the string for creating HKWMentionsAttribute

> Another Way

we can also use "unicodeScalars.count" to calculate correct length of string

let myNSRange = NSRange(location: aStartIndex, length: aStrName.unicodeScalars.count)

Happy coding!! 🎉

bkoatz commented 3 years ago

Please feel free tp put up a PR, including tests :)