1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-30 05:15:59 +02:00

Feature: Multi-Cursors

This commit is contained in:
Chernyavsky Andrey 2025-05-04 07:59:10 +05:00
parent 1e528cba95
commit c6fa2b8e79
9 changed files with 1776 additions and 530 deletions

View file

@ -138,8 +138,47 @@ namespace Beefy.utils
mCurCost = 0;
}
bool TryMerge(UndoAction action)
{
var currentBatchEnd = action as UndoBatchEnd;
if (currentBatchEnd == null)
return false;
var currentBatchStart = currentBatchEnd.mBatchStart as UndoBatchStart;
var prevBatchEndIdx = mUndoList.IndexOf(currentBatchStart) - 1;
if (prevBatchEndIdx <= 0)
return false;
var prevBatchEnd = mUndoList[prevBatchEndIdx] as UndoBatchEnd;
if (prevBatchEnd == null)
return false;
var prevBatchStart = prevBatchEnd.mBatchStart as UndoBatchStart;
if (prevBatchStart == null)
return false;
if (prevBatchStart.Merge(currentBatchStart) == false)
return false;
mUndoList.Remove(currentBatchStart);
mUndoList.Remove(currentBatchEnd);
mUndoList.Remove(prevBatchEnd);
mUndoList.Add(prevBatchEnd);
delete currentBatchStart;
delete currentBatchEnd;
mUndoIdx = (.)mUndoList.Count;
Debug.WriteLine("SUCCESS: Merged");
return true;
}
public void Add(UndoAction action, bool allowMerge = true)
{
if ((allowMerge) && (TryMerge(action)))
return;
if (mFreezeDeletes == 0)
mCurCost += action.GetCost();
if (action is IUndoBatchStart)