MCPcopy Create free account
hub / github.com/Palm1r/QodeAssist / undoAllEditsForRequest

Method undoAllEditsForRequest

context/ChangesManager.cpp:880–963  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

878}
879
880bool ChangesManager::undoAllEditsForRequest(const QString &requestId, QString *errorMsg)
881{
882 QMutexLocker locker(&m_mutex);
883
884 if (!m_requestEdits.contains(requestId)) {
885 LOG_MESSAGE(QString("No edits found for request: %1").arg(requestId));
886 return true;
887 }
888
889 const RequestEdits &reqEdits = m_requestEdits[requestId];
890 QStringList failedUndos;
891 int successCount = 0;
892
893 LOG_MESSAGE(QString("Undoing %1 edits for request: %2")
894 .arg(reqEdits.editIds.size()).arg(requestId));
895
896 for (int i = reqEdits.editIds.size() - 1; i >= 0; --i) {
897 const QString &editId = reqEdits.editIds[i];
898
899 if (!m_fileEdits.contains(editId)) {
900 LOG_MESSAGE(QString("Edit not found during undo: %1").arg(editId));
901 continue;
902 }
903
904 FileEdit &edit = m_fileEdits[editId];
905
906 if (edit.status == Archived) {
907 LOG_MESSAGE(QString("Skipping archived edit: %1").arg(editId));
908 continue;
909 }
910
911 if (edit.status != Applied) {
912 LOG_MESSAGE(QString("Edit %1 is not applied (status: %2), skipping").arg(editId).arg(edit.status));
913 continue;
914 }
915
916 QString filePathCopy = edit.filePath;
917 QString oldContentCopy = edit.oldContent;
918 QString newContentCopy = edit.newContent;
919
920 locker.unlock();
921
922 LOG_MESSAGE(QString("Undoing edit %1 using REVERSE fragment replacement (mass undo)").arg(editId));
923
924 QString errMsg;
925 bool isAppend = oldContentCopy.isEmpty();
926 bool success = performFragmentReplacement(
927 filePathCopy, newContentCopy, oldContentCopy, isAppend, &errMsg, true);
928
929 locker.relock();
930
931 if (success) {
932 edit.status = Rejected;
933 edit.statusMessage = errMsg.isEmpty() ? "Undone by mass undo" : errMsg;
934 edit.wasAutoApplied = false;
935 successCount++;
936
937 locker.unlock();

Callers 1

Calls 3

sizeMethod · 0.80
appendMethod · 0.80
isEmptyMethod · 0.45

Tested by

no test coverage detected