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,27 +179,33 @@ void CCTextFieldTTF::insertText(const char * text, int len)
|
|||
len = nPos;
|
||||
sInsert.erase(nPos);
|
||||
}
|
||||
if (len <= 0)
|
||||
|
||||
if (len > 0)
|
||||
{
|
||||
// close keyboard
|
||||
CCEGLView * pGlView = CCDirector::sharedDirector()->getOpenGLView();
|
||||
if (pGlView)
|
||||
if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, sInsert.c_str(), len))
|
||||
{
|
||||
pGlView->setIMEKeyboardState(false);
|
||||
// delegate doesn't want insert text
|
||||
return;
|
||||
}
|
||||
|
||||
m_nCharCount += _calcCharCount(sInsert.c_str());
|
||||
std::string sText(*m_pInputText);
|
||||
sText.append(sInsert);
|
||||
setString(sText.c_str());
|
||||
}
|
||||
|
||||
if (sInsert.npos == nPos) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, sInsert.c_str(), len))
|
||||
// '\n' has inserted, let delegate process first
|
||||
if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, "\n", 1))
|
||||
{
|
||||
// delegate doesn't want insert text
|
||||
return;
|
||||
}
|
||||
|
||||
m_nCharCount += _calcCharCount(sInsert.c_str());
|
||||
std::string sText(*m_pInputText);
|
||||
sText.append(sInsert);
|
||||
setString(sText.c_str());
|
||||
// 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