mirror of https://github.com/axmolengine/axmol.git
fixed a bug: TextInputTextWithAction can't stop CCTextFieldTTF's action when click enter button.
This commit is contained in:
parent
ec27d588a6
commit
b8a9db98dc
|
@ -179,17 +179,9 @@ void CCTextFieldTTF::insertText(const char * text, int len)
|
|||
len = nPos;
|
||||
sInsert.erase(nPos);
|
||||
}
|
||||
if (len <= 0)
|
||||
{
|
||||
// close keyboard
|
||||
CCEGLView * pGlView = CCDirector::sharedDirector()->getOpenGLView();
|
||||
if (pGlView)
|
||||
{
|
||||
pGlView->setIMEKeyboardState(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (len > 0)
|
||||
{
|
||||
if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, sInsert.c_str(), len))
|
||||
{
|
||||
// delegate doesn't want insert text
|
||||
|
@ -200,6 +192,20 @@ void CCTextFieldTTF::insertText(const char * text, int len)
|
|||
std::string sText(*m_pInputText);
|
||||
sText.append(sInsert);
|
||||
setString(sText.c_str());
|
||||
}
|
||||
|
||||
if (sInsert.npos == nPos) {
|
||||
return;
|
||||
}
|
||||
|
||||
// '\n' has inserted, let delegate process first
|
||||
if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, "\n", 1))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// if lelegate hasn't process, detach with ime as default
|
||||
detachWithIME();
|
||||
}
|
||||
|
||||
void CCTextFieldTTF::deleteBackward()
|
||||
|
|
|
@ -368,18 +368,18 @@ bool TextFieldTTFActionTest::onTextFieldDetachWithIME(CCTextFieldTTF * pSender)
|
|||
|
||||
bool TextFieldTTFActionTest::onTextFieldInsertText(CCTextFieldTTF * pSender, const char * text, int nLen)
|
||||
{
|
||||
// if insert enter, treat as default to detach with ime
|
||||
if ('\n' == *text)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// if the textfield's char count more than m_nCharLimit, doesn't insert text anymore.
|
||||
if (pSender->getCharCount() >= m_nCharLimit)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// if insert enter, treat as default
|
||||
if ('\n' == *text)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// create a insert text sprite and do some action
|
||||
CCLabelTTF * label = CCLabelTTF::labelWithString(text, FONT_NAME, FONT_SIZE);
|
||||
this->addChild(label);
|
||||
|
|
Loading…
Reference in New Issue