1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Ranges: Store more information in Split and Change operations

This allows implementing more sophisticated logic in types wrapping
Ranges and RangedValue objects.
This commit is contained in:
attila 2025-01-27 18:08:50 +01:00 committed by Attila Szarvas
parent ef840b7472
commit 43608a5208

View file

@ -70,9 +70,15 @@ struct Ranges final
struct Split
{
explicit Split (size_t x) : index { x } {}
Split (size_t x, Range<int64> leftRangeIn, Range<int64> rightRangeIn)
: index { x },
leftRange { leftRangeIn },
rightRange { rightRangeIn }
{}
size_t index;
Range<int64> leftRange;
Range<int64> rightRange;
};
struct Erase
@ -84,9 +90,15 @@ struct Ranges final
struct Change
{
explicit Change (size_t x) : index { x } {}
Change (size_t x, Range<int64> oldRangeIn, Range<int64> newRangeIn)
: index { x },
oldRange { oldRangeIn },
newRange { newRangeIn }
{}
size_t index;
Range<int64> oldRange;
Range<int64> newRange;
};
};
@ -137,7 +149,9 @@ struct Ranges final
if (elem.getStart() == i)
return {};
ops = withOperationsFrom (ops, Ops::Split { *elemIndex });
ops = withOperationsFrom (ops, Ops::Split { *elemIndex,
elem.withEnd (i),
elem.withStart (i) });
const auto oldLength = elem.getLength();
elem.setEnd (i);
@ -202,8 +216,9 @@ struct Ranges final
for (auto it = shiftStartingFrom; it < ranges.end(); ++it)
{
const auto oldRange = *it;
*it += amount;
ops = withOperationsFrom (ops, Ops::Change { getIndex (it) });
ops = withOperationsFrom (ops, Ops::Change { getIndex (it), oldRange, *it });
}
return ops;
@ -286,8 +301,9 @@ struct Ranges final
Operations ops;
ops = withOperationsFrom (ops, Ops::Change { start });
const auto oldRange = ranges[start];
ranges[start].setEnd (ranges[end].getEnd());
ops = withOperationsFrom (ops, Ops::Change { start, oldRange, ranges[start] });
ops = withOperationsFrom (ops, Ops::Erase { { end, end + 1 } });