MCPcopy Create free account
hub / github.com/axmolengine/axmol / insertText

Method insertText

core/ui/UITextFieldEx.cpp:534–597  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

532}
533
534void TextFieldEx::insertText(const char* text, size_t len)
535{
536 if (!_editable || !this->_enabled)
537 {
538 return;
539 }
540
541 if (_charLimit > 0 && _charCount >= _charLimit)
542 { // regard zero as unlimited
543 axbeep(0);
544 return;
545 }
546
547 int nb;
548 auto n = _truncateUTF8String(text, static_cast<int>(_charLimit - _charCount), nb);
549
550 std::string insert(text, nb);
551
552 // insert \n means input end
553 auto pos = insert.find('\n');
554 if (insert.npos != pos)
555 {
556 len = pos;
557 insert.erase(pos);
558 }
559
560 if (len > 0)
561 {
562 // if (_delegate && _delegate->onTextFieldInsertText(this, insert.c_str(), len))
563 //{
564 // // delegate doesn't want to insert text
565 // return;
566 // }
567
568 _charCount += n; // _calcCharCount(insert.c_str());
569 std::string sText(_inputText);
570 sText.insert(_insertPos, insert); // original is: sText.append(insert);
571
572 // bool needUpdatePos
573 this->setString(sText);
574 while (n-- > 0)
575 __moveCursor(1);
576
577 // this->contentDirty = true;
578 // __updateCursorPosition();
579
580 if (this->onTextModify)
581 this->onTextModify();
582 }
583
584 if (insert.npos == pos)
585 {
586 return;
587 }
588
589 // '\n' inserted, let delegate process first
590 /*if (_delegate && _delegate->onTextFieldInsertText(this, "\n", 1))
591 {

Callers

nothing calls this directly

Calls 6

setStringMethod · 0.95
closeIMEMethod · 0.95
_truncateUTF8StringFunction · 0.85
findMethod · 0.45
eraseMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected