Question

I'm using Rangy plugin and 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?

Was it helpful?

Solution

I answered this on the Rangy forum. In case that link stops working, here's what I wrote:


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:

sel.expand("word", {
    wordOptions: {
        wordRegex: XRegExp("[\\p{L}\\d]+('[\\p{L}\\d]+)*", "gi")
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top