bool Editbox::performPaste(Clipboard& clipboard) { if (isReadOnly()) return false; String clipboardText = clipboard.getText(); if (clipboardText.empty()) return false; // backup current text String tmp(getText()); UndoHandler::UndoAction undoSelection; undoSelection.d_type = UndoHandler::UAT_DELETE; undoSelection.d_startIdx = getSelectionStart(); undoSelection.d_text = tmp.substr(getSelectionStart(), getSelectionLength()); tmp.erase(getSelectionStart(), getSelectionLength()); // if there is room if (tmp.length() < d_maxTextLen) { UndoHandler::UndoAction undo; undo.d_type = UndoHandler::UAT_INSERT; undo.d_startIdx = getCaretIndex(); undo.d_text = clipboardText; tmp.insert(getSelectionStart(), clipboardText); if (handleValidityChangeForString(tmp)) { // erase selection using mode that does not modify getText() // (we just want to update state) eraseSelectedText(false); // advance caret (done first so we can "do stuff" in event // handlers!) d_caretPos += clipboardText.length(); // set text to the newly modified string setText(tmp); d_undoHandler->addUndoHistory(undo); if (getSelectionLength() > 0) d_undoHandler->addUndoHistory(undoSelection); return true; } } return false; }
//----------------------------------------------------------------------------// bool Editbox::performPaste(Clipboard& clipboard) { if (isReadOnly()) return false; String clipboardText = clipboard.getText(); if (clipboardText.empty()) return false; // backup current text String tmp(getText()); tmp.erase(getSelectionStartIndex(), getSelectionLength()); // if there is room if (tmp.length() < d_maxTextLen) { tmp.insert(getSelectionStartIndex(), clipboardText); if (handleValidityChangeForString(tmp)) { // erase selection using mode that does not modify getText() // (we just want to update state) eraseSelectedText(false); // advance caret (done first so we can "do stuff" in event // handlers!) d_caretPos += clipboardText.length(); // set text to the newly modified string setText(tmp); return true; } } return false; }