mickael9
Full Member
  
Posts: 117 Reputation: 3
33 / / 
Joined: Jul 2005
|
RE: Replace EditText
quote: Originally posted by ChristianAMD3000
Hi @ all friends
i got a big problem
i want replace the words in EditText-box during i write something.
e.g if i write "hallo"--> it must be changed in "Hello".
i used OnEvent_ChatWndSendMessage(); command and its working
but that is not realy usefull becouse i cant change the words if i make a mistake..
i think u all get it what my problem is.
it would be verry greatfull if somebody can help me 
(Sorry My english )
Christian
Hi,
code: var Params = {};
var ParamCount = 0;
var Replacements = {
"hallo" : "hello"
};
function OnEvent_ChatWndEditKeyDown(oChatWnd, nKeyCode, bCtrl, bShift)
{
var sTimerId = "InlineRepl_" + (++ParamCount);
Params[sTimerId] = oChatWnd;
MsgPlus.AddTimer(sTimerId,100);
}
function OnEvent_Timer(sTimerId)
{
if (sTimerId.substr(0, 11) == "InlineRepl_")
{
var Wnd = Params[sTimerId];
var nSelStart = Wnd.EditText_GetCurSelStart();
var nSelEnd = Wnd.EditText_GetCurSelEnd();
var nOldLength = Wnd.EditText.length;
var sText = Wnd.EditText;
for (sKey in Replacements)
{
sText = sText.replace(sKey,Replacements[sKey]);
}
if (sText.length < nOldLength)
{
nSelStart -= (nOldLength - sText.length);
nSelEnd -= (nOldLength - sText.length);
}
else if (sText.length > nOldLength)
{
nSelStart += (sText.length - nOldLength);
nSelEnd += (sText.length - nOldLength);
}
Wnd.EditText = sText;
Wnd.EditText_SetCurSel(nSelStart, nSelEnd);
ParamCount--;
delete(Params[sTimerId]);
}
}
|
|