Skip to content

Using 'ZERO WIDTH JOINER' char instead of "|" for offset calculations#61

Open
ilanbm wants to merge 2 commits intoichord:masterfrom
ilanbm:master
Open

Using 'ZERO WIDTH JOINER' char instead of "|" for offset calculations#61
ilanbm wants to merge 2 commits intoichord:masterfrom
ilanbm:master

Conversation

@ilanbm
Copy link

@ilanbm ilanbm commented Nov 28, 2018

I noticed that Caret.js doesnt work well with languages that display connected chars such as arabic/persian/malayalam etc..

The code uses the char "|" to check the offset of a certain location. you should use the ZWJ char:
https://en.wikipedia.org/wiki/Zero-width_joiner

The advantage of using the 'zero width joiner' char is that:

  • it has zero width as oppose to "|"
  • and mainly it doesn't break chars that connect...

Example:
العربية
الع|ربية
notice that "|" break the word and it's offset is different than it suppose to be

It might also solve issues with offset of numbers chars on RTL languages.
12345
will appear on RTL with "|" char: 345|12

Note: I'm just suggesting that on the way... I didn't check the code (forked and edited directly on github) and I didn't change getPosition function since it uses span element that wraps the "|" char and having an element instead of a text node with the ZWJ might not work - and still separate connected chars.

Please check and update - for people who use those languages (quite a lot)

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.

1 participant