MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / onPaste

Method onPaste

Engine/source/gui/controls/guiTextEditCtrl.cpp:508–554  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

506}
507
508void GuiTextEditCtrl::onPaste()
509{
510 //first, make sure there's something in the clipboard to copy...
511 const UTF8 *clipboard = Platform::getClipboard();
512 if(dStrlen(clipboard) <= 0)
513 return;
514
515 //save the current state
516 saveUndoState();
517
518 //delete anything hilited
519 if (mBlockEnd > 0)
520 {
521 mTextBuffer.cut(mBlockStart, mBlockEnd - mBlockStart);
522 mCursorPos = mBlockStart;
523 mBlockStart = 0;
524 mBlockEnd = 0;
525 }
526
527 // We'll be converting to UTF16, and maybe trimming the string,
528 // so let's use a StringBuffer, for convinience.
529 StringBuffer pasteText(clipboard);
530
531 // Space left after we remove the highlighted text
532 S32 stringLen = mTextBuffer.length();
533
534 // Trim down to fit in a buffer of size mMaxStrLen
535 S32 pasteLen = pasteText.length();
536
537 if(stringLen + pasteLen > mMaxStrLen)
538 {
539 pasteLen = mMaxStrLen - stringLen;
540
541 pasteText.cut(pasteLen, pasteText.length() - pasteLen);
542 }
543
544 if (mCursorPos == stringLen)
545 {
546 mTextBuffer.append(pasteText);
547 }
548 else
549 {
550 mTextBuffer.insert(mCursorPos, pasteText);
551 }
552
553 mCursorPos += pasteLen;
554}
555
556void GuiTextEditCtrl::onUndo()
557{

Callers

nothing calls this directly

Calls 5

cutMethod · 0.80
dStrlenFunction · 0.50
lengthMethod · 0.45
appendMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected