Skip to content

Commit cb5633d

Browse files
committed
Don't create undo history item for a paste that does nothing.
1 parent 3f36706 commit cb5633d

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

src/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,35 +175,26 @@ public void InsertInput(int frame, IEnumerable<IController> inputStates)
175175

176176
public void CopyOverInput(int frame, IEnumerable<IController> inputStates)
177177
{
178-
int firstChangedFrame = -1;
179178
var states = inputStates.ToList();
180179

181180
bool endBatch = ChangeLog.BeginNewBatch($"Copy Over Input: {frame}", true);
182181

183182
if (Log.Count < states.Count + frame)
184183
{
185-
firstChangedFrame = Log.Count;
186184
ExtendMovieForEdit(states.Count + frame - Log.Count);
187185
}
188186

189187
ChangeLog.AddGeneralUndo(frame, frame + states.Count - 1, $"Copy Over Input: {frame}");
190188
for (int i = 0; i < states.Count; i++)
191189
{
192-
var entry = Bk2LogEntryGenerator.GenerateLogEntry(states[i]);
193-
if ((firstChangedFrame == -1 || firstChangedFrame > frame + i) && Log[frame + i] != entry)
194-
{
195-
firstChangedFrame = frame + i;
196-
}
197-
198-
Log[frame + i] = entry;
190+
Log[frame + i] = Bk2LogEntryGenerator.GenerateLogEntry(states[i]);
199191
}
200-
ChangeLog.SetGeneralRedo();
192+
int firstChangedFrame = ChangeLog.SetGeneralRedo();
201193

202194
if (endBatch) ChangeLog.EndBatch();
203195

204196
if (firstChangedFrame != -1)
205197
{
206-
// TODO: Throw out the undo action if there are no changes.
207198
InvalidateAfter(firstChangedFrame);
208199
}
209200
}

src/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public interface IMovieChangeLog
4141
int MaxSteps { get; set; }
4242

4343
void AddGeneralUndo(int first, int last, string name = "");
44-
void SetGeneralRedo();
44+
int SetGeneralRedo();
4545
void AddBoolToggle(int frame, string button, bool oldState, string name = "");
4646
void AddAxisChange(int frame, string button, int oldState, int newState, string name = "");
4747
void AddMarkerChange(TasMovieMarker newMarker, int oldPosition = -1, string oldMessage = "", string name = "");
@@ -263,13 +263,25 @@ public void AddGeneralUndo(int first, int last, string name = "")
263263
}
264264
}
265265

266-
public void SetGeneralRedo()
266+
public int SetGeneralRedo()
267267
{
268268
if (IsRecording)
269269
{
270270
Debug.Assert(_lastGeneral == LatestBatch.Count - 1, "GeneralRedo should not see changes from other undo actions.");
271-
((MovieAction) LatestBatch[_lastGeneral]).SetRedoLog(_movie);
271+
int changed = ((MovieAction) LatestBatch[_lastGeneral]).SetRedoLog(_movie);
272+
if (changed == -1)
273+
{
274+
LatestBatch.RemoveAt(_lastGeneral);
275+
if (LatestBatch.Count == 0 && !_recordingBatch)
276+
{
277+
// Remove this undo item
278+
_recordingBatch = true;
279+
EndBatch();
280+
}
281+
}
282+
return changed;
272283
}
284+
return -1;
273285
}
274286

275287
public void AddBoolToggle(int frame, string button, bool oldState, string name = "")
@@ -387,14 +399,21 @@ public MovieAction(int firstFrame, int lastFrame, ITasMovie movie)
387399
_bindMarkers = movie.BindMarkersToInput;
388400
}
389401

390-
public void SetRedoLog(ITasMovie movie)
402+
/// <returns>Returns the first frame that has changed, or -1 if no changes.</returns>
403+
public int SetRedoLog(ITasMovie movie)
391404
{
392405
_redoLength = Math.Min(LastFrame + 1, movie.InputLogLength) - FirstFrame;
393406
_newLog = new List<string>(_redoLength);
407+
int changed = Math.Min(_redoLength, _undoLength);
394408
for (int i = 0; i < _redoLength; i++)
395409
{
396-
_newLog.Add(movie.GetInputLogEntry(FirstFrame + i));
410+
string newEntry = movie.GetInputLogEntry(FirstFrame + i);
411+
_newLog.Add(newEntry);
412+
if (i < changed && newEntry != _oldLog[i]) changed = i;
397413
}
414+
415+
if (changed == _redoLength && changed == _undoLength) return -1;
416+
else return changed + FirstFrame;
398417
}
399418

400419
public void Undo(ITasMovie movie)

0 commit comments

Comments
 (0)