| 346 | } |
| 347 | |
| 348 | void TextField::insertText(std::string text) { |
| 349 | // Rack uses UNIX newlines so remove all CR characters |
| 350 | text.erase(std::remove(text.begin(), text.end(), '\r'), text.end()); |
| 351 | |
| 352 | bool changed = false; |
| 353 | if (cursor != selection) { |
| 354 | // Delete selected text |
| 355 | int begin = std::min(cursor, selection); |
| 356 | int len = std::abs(selection - cursor); |
| 357 | this->text.erase(begin, len); |
| 358 | cursor = selection = begin; |
| 359 | changed = true; |
| 360 | } |
| 361 | if (!text.empty()) { |
| 362 | this->text.insert(cursor, text); |
| 363 | cursor += text.size(); |
| 364 | selection = cursor; |
| 365 | changed = true; |
| 366 | } |
| 367 | if (changed) { |
| 368 | ChangeEvent eChange; |
| 369 | onChange(eChange); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | void TextField::copyClipboard() { |
| 374 | if (cursor == selection) |