From 02d4712e9c7e2844d99d681eef6dbf1a82b2ea70 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Fri, 17 Jun 2022 02:21:07 -0500 Subject: [PATCH] implement undo in find and replace --- src/gui/findReplace.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/gui/findReplace.cpp b/src/gui/findReplace.cpp index 5dae95bc..c0d59c49 100644 --- a/src/gui/findReplace.cpp +++ b/src/gui/findReplace.cpp @@ -190,7 +190,6 @@ void FurnaceGUI::doFind() { } /* issues with the find and replace function: - - doesn't mark the module as modified - can't undo - replace notes to anything starting from C-0 to lower notes will have an octave higher, so set it to replace to C-0 it will becom C-1, b_1 will become B-0 and so on */ @@ -202,6 +201,12 @@ void FurnaceGUI::doReplace() { bool* touched[DIV_MAX_CHANS]; memset(touched,0,DIV_MAX_CHANS*sizeof(bool*)); + UndoStep us; + us.type=GUI_UNDO_REPLACE; + + short prevVal[32]; + memset(prevVal,0,32*sizeof(short)); + for (FurnaceGUIQueryResult& i: curQueryResults) { int patIndex=e->song.subsong[i.subsong]->orders.ord[i.x][i.order]; DivPattern* p=e->song.subsong[i.subsong]->pat[i.x].getPattern(patIndex,true); @@ -211,6 +216,9 @@ void FurnaceGUI::doReplace() { } if (touched[i.x][(patIndex<<8)|i.y]) continue; touched[i.x][(patIndex<<8)|i.y]=true; + + memcpy(prevVal,p->data[i.y],32*sizeof(short)); + if (queryReplaceNoteDo) { switch (queryReplaceNoteMode) { case GUI_QUERY_REPLACE_SET: @@ -400,6 +408,13 @@ void FurnaceGUI::doReplace() { } } } + + // issue undo step + for (int j=0; j<32; j++) { + if (p->data[i.y][j]!=prevVal[j]) { + us.pat.push_back(UndoPatternData(i.subsong,i.x,patIndex,i.y,j,prevVal[j],p->data[i.y][j])); + } + } } for (int i=0; isettings.maxUndoSteps) undoHist.pop_front(); + } } #define FIRST_VISIBLE(x) (x==GUI_QUERY_MATCH || x==GUI_QUERY_MATCH_NOT || x==GUI_QUERY_RANGE || x==GUI_QUERY_RANGE_NOT)