diff --git a/BeefLibs/Beefy2D/src/utils/UndoManager.bf b/BeefLibs/Beefy2D/src/utils/UndoManager.bf index fdeb8b89..b76d7209 100644 --- a/BeefLibs/Beefy2D/src/utils/UndoManager.bf +++ b/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"); + } + } } } diff --git a/BeefLibs/Beefy2D/src/widgets/EditWidget.bf b/BeefLibs/Beefy2D/src/widgets/EditWidget.bf index f6f9ad78..6bf931a3 100644 --- a/BeefLibs/Beefy2D/src/widgets/EditWidget.bf +++ b/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 diff --git a/IDE/src/IDEApp.bf b/IDE/src/IDEApp.bf index 60f5e4db..c60ec77e 100644 --- a/IDE/src/IDEApp.bf +++ b/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); } //////////