Rangy expands for cyrillic

68 views
Skip to first unread message

Ivan Shcherbakov

unread,
Oct 18, 2013, 8:19:51 AM10/18/13
to ra...@googlegroups.com
Hello! I'm using textRange module and there is a problem. Then I'm using selection.expand('word') on the such text "расстояние {москва} геленджика" (selected text in brackets) Rangy expands it to the adjacent words and I got such selected texts "{расстояние москва геленджика}". But in this case I already have a selected word! I just need expanding to {москва} in м{оск}ва situations.
 
How can I solve this? What is the difference between different languages, that causing this problem?

Tim Down

unread,
Oct 22, 2013, 5:41:50 AM10/22/13
to rangy
Hi Ivan,

It's set up for Latin script by default, but you can specify a regular expression in the expand() method. The default is /[a-z0-9]+('[a-z0-9]+)*/gi, which is pretty basic but provided as a reasonable default for English.

A simple example:

  sel.expand("word", { wordOptions: { wordRegex:/[a-z0-9\u0400-\u04FF]+('[a-z0-9\u0400-\u04FF]+)*/gi } } );

I'm no expert in Cyrillic so I've just added some Cyrillic characters to the character classes in the regular expression for illustration purposes. You could do better using XRegExp and its Unicode plugin (http://xregexp.com/):

  sel.expand("word", { wordOptions: { wordRegex: XRegExp("[\\p{L}\\d]+('[\\p{L}\\d]+)*", "gi") } } );

Tim



On 18 October 2013 13:19, Ivan Shcherbakov <ispr...@gmail.com> wrote:
Hello! I'm using textRange module and there is a problem. Then I'm using selection.expand('word') on the such text "расстояние {москва} геленджика" (selected text in brackets) Rangy expands it to the adjacent words and I got such selected texts "{расстояние москва геленджика}". But in this case I already have a selected word! I just need expanding to {москва} in м{оск}ва situations.
 
How can I solve this? What is the difference between different languages, that causing this problem?

--
You received this message because you are subscribed to the Google Groups "rangy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rangy+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Ivan Shcherbakov

unread,
Oct 22, 2013, 9:35:19 AM10/22/13
to ra...@googlegroups.com
Thanks! It solves my problem!

BTW, you made a great plugin!)
Reply all
Reply to author
Forward
0 new messages