The DataChange constructor must no longer make any changes to the buffer.

DataChange::Apply() will now remember the string instead, so that undo/redo
will work correctly even if the underlying data has changed in the mean time.
DataEditor::AddChange() will now apply the change as well.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6103 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2004-01-16 04:57:20 +00:00
parent 5af91ef5cb
commit 73c630c948
+4 -7
View File
@@ -54,13 +54,7 @@ ReplaceChange::ReplaceChange(off_t bufferOffset, uint8 *buffer,
fNewData = (uint8 *)malloc(size);
fOldData = (uint8 *)malloc(size);
if (fNewData != NULL && fOldData != NULL) {
// Save old data, and replace the data in the supplied buffer.
// Note, the buffer must be large enough to hold the changes
// at this point!
memcpy(fNewData, data, size);
memcpy(fOldData, buffer + offset - bufferOffset, size);
memcpy(buffer + offset - bufferOffset, fNewData, size);
fSize = size;
} else
fSize = 0;
@@ -110,7 +104,8 @@ ReplaceChange::Apply(off_t bufferOffset, uint8 *buffer, size_t bufferSize)
if (size == 0)
return;
// now we can safely change the buffer!
// now we can safely exchange the buffer!
memcpy(fOldData + dataOffset, buffer + offset - bufferOffset, size);
memcpy(buffer + offset - bufferOffset, fNewData + dataOffset, size);
}
@@ -252,6 +247,8 @@ DataEditor::AddChange(DataChange *change)
fChanges.AddItem(change);
fLastChange = change;
fLastChange->Apply(fRealViewOffset, fView, fRealViewSize);
}