| 252 | } |
| 253 | |
| 254 | void TextFieldTTF::insertText(const char* text, size_t len) |
| 255 | { |
| 256 | std::string insert(text, len); |
| 257 | |
| 258 | // insert \n means input end |
| 259 | int pos = static_cast<int>(insert.find(StringUtils::AsciiCharacters::NewLine)); |
| 260 | if ((int)insert.npos != pos) |
| 261 | { |
| 262 | len = pos; |
| 263 | insert.erase(pos); |
| 264 | } |
| 265 | |
| 266 | if (len > 0) |
| 267 | { |
| 268 | if (_delegate && _delegate->onTextFieldInsertText(this, insert.c_str(), len)) |
| 269 | { |
| 270 | // delegate doesn't want to insert text |
| 271 | return; |
| 272 | } |
| 273 | |
| 274 | std::size_t countInsertChar = StringUtils::countUTF8Chars(insert); |
| 275 | _charCount += countInsertChar; |
| 276 | |
| 277 | if (_cursorEnabled) |
| 278 | { |
| 279 | std::string sText; |
| 280 | sText.reserve(_inputText.length() + insert.length()); |
| 281 | sText += _inputText; |
| 282 | auto pos = StringUtils::getUTF8ByteOffset(sText, _cursorPosition); |
| 283 | if (pos != std::string::npos) |
| 284 | sText.insert(pos, insert); |
| 285 | else |
| 286 | sText += insert; |
| 287 | |
| 288 | setCursorPosition(_cursorPosition + countInsertChar); |
| 289 | |
| 290 | setString(sText); |
| 291 | } |
| 292 | else |
| 293 | { |
| 294 | std::string sText(_inputText); |
| 295 | sText.append(insert); |
| 296 | setString(sText); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | if ((int)insert.npos == pos) |
| 301 | { |
| 302 | return; |
| 303 | } |
| 304 | |
| 305 | // '\n' inserted, let delegate process first |
| 306 | if (_delegate && _delegate->onTextFieldInsertText(this, "\n", 1)) |
| 307 | { |
| 308 | return; |
| 309 | } |
| 310 | |
| 311 | // if delegate hasn't processed, detach from IME by default |
nothing calls this directly
no test coverage detected