From 2bcff60c2954bc9ff2633df1f1165ed6a9c833a0 Mon Sep 17 00:00:00 2001 From: dmcoles Date: Tue, 16 Jul 2024 11:13:15 +0100 Subject: [PATCH] don't create undo point when no changes have been made --- rebuild.e | 18 ++++++++++++++++-- stringStreamer.e | 13 +++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/rebuild.e b/rebuild.e index b2e0570..2f74b79 100644 --- a/rebuild.e +++ b/rebuild.e @@ -2936,6 +2936,8 @@ ENDPROC PROC addUndo() DEF strStream:PTR TO stringStreamer + DEF prevStream:PTR TO stringStreamer + DEF doAdd=FALSE,i WHILE undoPos<(undoData.count()-1) strStream:=undoData.item(undoData.count()-1) END strStream @@ -2946,8 +2948,20 @@ PROC addUndo() NEW strStream.create() saveStream(strStream) - undoData.add(strStream) - undoPos++ + + IF (undoData.count()=0) + doAdd:=TRUE + ELSE + prevStream:=undoData.item(undoData.count()-1) + IF prevStream.compareTo(strStream)=FALSE THEN doAdd:=TRUE + ENDIF + + IF doAdd + undoData.add(strStream) + undoPos++ + ELSE + END strStream + ENDIF menuDisable(win,MENU_EDIT,MENU_EDIT_UNDO,0,undoPos=0) menuDisable(win,MENU_EDIT,MENU_EDIT_REDO,0,undoPos>=(undoData.count()-1)) diff --git a/stringStreamer.e b/stringStreamer.e index 5858e7e..871a280 100644 --- a/stringStreamer.e +++ b/stringStreamer.e @@ -58,3 +58,16 @@ PROC reset() OF stringStreamer self.currpos:=0 ENDPROC +PROC compareTo(otherStream:PTR TO stringStreamer) OF stringStreamer + DEF i + + IF otherStream.data.count()<>self.data.count() + RETURN FALSE + ELSE + i:=otherStream.data.count()-1 + WHILE (i>=0) + IF StrCmp(otherStream.data.item(i),self.data.item(i))=FALSE THEN RETURN FALSE + i-- + ENDWHILE + ENDIF +ENDPROC TRUE