| 999 | } |
| 1000 | |
| 1001 | bool EditBox::commandUndo() |
| 1002 | { |
| 1003 | if (mVectorUndoChangeInfo.empty()) |
| 1004 | return false; |
| 1005 | |
| 1006 | resetSelect(); |
| 1007 | |
| 1008 | // save last undo info |
| 1009 | VectorChangeInfo info = mVectorUndoChangeInfo.back(); |
| 1010 | // move undo info to redo |
| 1011 | mVectorUndoChangeInfo.pop_back(); |
| 1012 | mVectorRedoChangeInfo.push_back(info); |
| 1013 | |
| 1014 | UString::utf32string text = getRealString().asUTF32(); |
| 1015 | |
| 1016 | // apply undo |
| 1017 | for (VectorChangeInfo::const_reverse_iterator iter = info.rbegin(); iter != info.rend(); ++iter) |
| 1018 | { |
| 1019 | const auto& change = *iter; |
| 1020 | switch (change.type) |
| 1021 | { |
| 1022 | case TextCommandInfo::COMMAND_INSERT: text.erase(change.start, change.text.size()); break; |
| 1023 | case TextCommandInfo::COMMAND_ERASE: text.insert(change.start, change.text); break; |
| 1024 | case TextCommandInfo::COMMAND_POSITION: |
| 1025 | mCursorPosition = change.undo; |
| 1026 | mTextLength = change.length; |
| 1027 | break; |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | setRealString(UString(text)); |
| 1032 | |
| 1033 | // restore cursor position |
| 1034 | if (mClientText != nullptr) |
| 1035 | mClientText->setCursorPosition(mCursorPosition); |
| 1036 | updateSelectText(); |
| 1037 | |
| 1038 | eventEditTextChange(this); |
| 1039 | |
| 1040 | return true; |
| 1041 | } |
| 1042 | |
| 1043 | bool EditBox::commandRedo() |
| 1044 | { |