소스 검색

Fixed undo text corruption bug

Brian Fiete 1 년 전
부모
커밋
6a5b0b49ed
3개의 변경된 파일68개의 추가작업 그리고 6개의 파일을 삭제
  1. 26 0
      BeefLibs/Beefy2D/src/utils/UndoManager.bf
  2. 34 6
      BeefLibs/Beefy2D/src/widgets/EditWidget.bf
  3. 8 0
      IDE/src/IDEApp.bf

+ 26 - 0
BeefLibs/Beefy2D/src/utils/UndoManager.bf

@@ -75,6 +75,11 @@ namespace Beefy.utils
 		{
 			return Math.Min(mBatchSize, 256); // Don't allow a large batch (ie: rename) to cause us to pull too much out of the undo buffer
 		}
+
+		public override void ToString(String strBuffer)
+		{
+			strBuffer.AppendF($"UndoBatchStart {mName}");
+		}
     }
 
     public class UndoBatchEnd : UndoAction, IUndoBatchEnd
@@ -95,6 +100,11 @@ namespace Beefy.utils
                 return mBatchStart;
             }
         }
+
+		public override void ToString(String strBuffer)
+		{
+			strBuffer.AppendF($"UndoBatchEnd {Name}");
+		}
     }
 
     public class UndoManager
@@ -307,5 +317,21 @@ namespace Beefy.utils
 		{
 			return mUndoIdx;
 		}
+
+		public override void ToString(String str)
+		{
+			for (int i < mUndoList.Count)
+			{
+				if (i == mUndoIdx)
+					str.Append(">");
+				else
+					str.Append(" ");
+
+				var entry = mUndoList[i];
+				str.AppendF($"{i}. {entry}");
+
+				str.Append("\n");
+			}
+		}
     }
 }

+ 34 - 6
BeefLibs/Beefy2D/src/widgets/EditWidget.bf

@@ -321,6 +321,14 @@ namespace Beefy.widgets
                 InsertTextAction insertTextAction = nextAction as InsertTextAction;
                 if (insertTextAction == null)
                     return false;
+
+				int curIdx = mCursorTextPos;
+				int nextIdx = insertTextAction.mCursorTextPos;
+				if ((nextIdx != curIdx + mText.Length) ||
+					(mText.EndsWith("\n")) ||
+					(insertTextAction.mText == "\n"))
+					return false;
+
                 if (insertTextAction.mSelection != null)
                 {
                     if (mSelection == null)
@@ -335,14 +343,9 @@ namespace Beefy.widgets
                     mSelectionText.Append(insertTextAction.mSelectionText);
                 }
 
-                int curIdx = mCursorTextPos;
-                int nextIdx = insertTextAction.mCursorTextPos;
                 mRestoreSelectionOnUndo &= insertTextAction.mRestoreSelectionOnUndo;
                 
-                if ((nextIdx != curIdx + mText.Length) ||
-                    (mText.EndsWith("\n")) ||
-                    (insertTextAction.mText == "\n"))
-                    return false;
+                
 
                 mText.Append(insertTextAction.mText);
                 return true;
@@ -374,6 +377,31 @@ namespace Beefy.widgets
                     editWidgetContent.mEditWidget.FinishScroll();
                 return true;
             }
+
+			public override void ToString(String strBuffer)
+			{
+				strBuffer.Append("InsertTextAction");
+				if (mText != null)
+				{
+					strBuffer.Append(" ");
+					mText.Quote(strBuffer);
+				}
+
+				strBuffer.AppendF($" CursorTextPos:{mCursorTextPos}");
+				strBuffer.AppendF(" Selection:");
+				if (mSelection != null)
+				{
+					strBuffer.AppendF($"{mSelection.Value.mStartPos}-{mSelection.Value.mEndPos}");
+				}
+				else
+					strBuffer.AppendF("null");
+
+				if (mSelectionText != null)
+				{
+					strBuffer.AppendF(" SelectionText:");
+					mSelectionText.Quote(strBuffer);
+				}
+			}
         }
 
         public class DeleteCharAction : TextAction

+ 8 - 0
IDE/src/IDEApp.bf

@@ -5902,6 +5902,14 @@ namespace IDE
 				internalEditMenu.AddMenuItem("Delayed Autocomplete", null, new (menu) => { ToggleCheck(menu, ref gApp.mDbgDelayedAutocomplete); }, null, null, true, gApp.mDbgDelayedAutocomplete ? 1 : 0);
 				internalEditMenu.AddMenuItem("Time Autocomplete", null, new (menu) => { ToggleCheck(menu, ref gApp.mDbgTimeAutocomplete); }, null, null, true, gApp.mDbgTimeAutocomplete ? 1 : 0);
 				internalEditMenu.AddMenuItem("Perf Autocomplete", null, new (menu) => { ToggleCheck(menu, ref gApp.mDbgPerfAutocomplete); }, null, null, true, gApp.mDbgPerfAutocomplete ? 1 : 0);
+				internalEditMenu.AddMenuItem("Dump Undo Buffer", null, new (menu) =>
+					{
+						if (var panel = GetActiveSourceViewPanel())
+						{
+							var str = panel.mEditWidget.mEditWidgetContent.mData.mUndoManager.ToString(.. scope .());
+							Debug.WriteLine(str);
+						}
+					}, null, null, true, gApp.mDbgPerfAutocomplete ? 1 : 0);
 			}
 
 			//////////