Set default keyboard layout (for other language) for a field
Igor de Oliveira Couto
igor at semperuna.com
Tue Feb 19 00:18:16 EST 2013
Jonathan, I couldn't resist, and ended up trying this out myself:
On 19/02/2013, at 3:42 PM, Igor de Oliveira Couto <igor at semperuna.com> wrote:
> For an more polished user experience, you can try developing a script that is more forgiving when the user mixes upper- and lower-case 'x's, like "Cx" and "cX". You can also try to develop a script that would do the replacing on 'textChanged' rather than on 'closeField', but you will then have to use 'the selectedChunk' and some basic maths in order not to loose the user's insertion point place in the text, as you replace the characters.
I managed to get a 'quick-and-dirty' version working, already. It will still need to be improved quite a bit, and cover cases I haven't thought of, but it seems to be a good starting point. Paste this in the script of a field:
on textChanged
local tSel
put the selectedChunk into tSel
set the htmlText of me to xSystemToUnicode(the htmlText of me)
select after tSel
end textChanged
function xSystemToUnicode pHTMLTxt
replace "cx" with "ĉ" in pHTMLTxt
replace "cX" with "ĉ" in pHTMLTxt
replace "Cx" with "Ĉ" in pHTMLTxt
replace "CX" with "Ĉ" in pHTMLTxt
replace "gx" with "ĝ" in pHTMLTxt
replace "gX" with "ĝ" in pHTMLTxt
replace "Gx" with "Ĝ" in pHTMLTxt
replace "GX" with "Ĝ" in pHTMLTxt
replace "hx" with "ĥ" in pHTMLTxt
replace "hX" with "ĥ" in pHTMLTxt
replace "Hx" with "Ĥ" in pHTMLTxt
replace "HX" with "Ĥ" in pHTMLTxt
replace "jx" with "ĵ" in pHTMLTxt
replace "jX" with "ĵ" in pHTMLTxt
replace "Jx" with "Ĵ" in pHTMLTxt
replace "JX" with "Ĵ" in pHTMLTxt
replace "sx" with "ŝ" in pHTMLTxt
replace "sX" with "ŝ" in pHTMLTxt
replace "Sx" with "Ŝ" in pHTMLTxt
replace "SX" with "Ŝ" in pHTMLTxt
replace "uxx" with "ŭ" in pHTMLTxt -- we don't want to have problems
replace "uxX" with "ŭ" in pHTMLTxt -- with English words like 'auxiliary'...
replace "uXX" with "ŭ" in pHTMLTxt
replace "uXx" with "ŭ" in pHTMLTxt
replace "Uxx" with "Ŭ" in pHTMLTxt
replace "UXx" with "Ŭ" in pHTMLTxt
replace "UxX" with "Ŭ" in pHTMLTxt
replace "UXX" with "Ŭ" in pHTMLTxt
return pHTMLTxt
end xSystemToUnicode
Then, try typing a sentence in Esperanto in the field, using the x-method, such as:
"Mi nomigxas Jocxjo!"
The letters should automagically convert from the x-system to the proper, accented characters, as you type. The function above also has built-in 'forgiveness' for mismatching the case of the 'x' - if you type an uppercase 'C' and a lowercase 'x', it will convert it to an uppercase 'Ĉ'.
I hope this helps!
--
Igor Couto
Sydney, Australia
More information about the use-livecode
mailing list