1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Fixed undo text corruption bug

This commit is contained in:
Brian Fiete 2024-04-27 08:24:55 -04:00
parent 1625d511be
commit 6a5b0b49ed
3 changed files with 68 additions and 6 deletions

View file

@ -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 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 public class UndoBatchEnd : UndoAction, IUndoBatchEnd
@ -95,6 +100,11 @@ namespace Beefy.utils
return mBatchStart; return mBatchStart;
} }
} }
public override void ToString(String strBuffer)
{
strBuffer.AppendF($"UndoBatchEnd {Name}");
}
} }
public class UndoManager public class UndoManager
@ -307,5 +317,21 @@ namespace Beefy.utils
{ {
return mUndoIdx; 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");
}
}
} }
} }

View file

@ -321,6 +321,14 @@ namespace Beefy.widgets
InsertTextAction insertTextAction = nextAction as InsertTextAction; InsertTextAction insertTextAction = nextAction as InsertTextAction;
if (insertTextAction == null) if (insertTextAction == null)
return false; 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 (insertTextAction.mSelection != null)
{ {
if (mSelection == null) if (mSelection == null)
@ -335,14 +343,9 @@ namespace Beefy.widgets
mSelectionText.Append(insertTextAction.mSelectionText); mSelectionText.Append(insertTextAction.mSelectionText);
} }
int curIdx = mCursorTextPos;
int nextIdx = insertTextAction.mCursorTextPos;
mRestoreSelectionOnUndo &= insertTextAction.mRestoreSelectionOnUndo; mRestoreSelectionOnUndo &= insertTextAction.mRestoreSelectionOnUndo;
if ((nextIdx != curIdx + mText.Length) ||
(mText.EndsWith("\n")) ||
(insertTextAction.mText == "\n"))
return false;
mText.Append(insertTextAction.mText); mText.Append(insertTextAction.mText);
return true; return true;
@ -374,6 +377,31 @@ namespace Beefy.widgets
editWidgetContent.mEditWidget.FinishScroll(); editWidgetContent.mEditWidget.FinishScroll();
return true; 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 public class DeleteCharAction : TextAction

View file

@ -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("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("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("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);
} }
////////// //////////