IEnumerable <TextAndHexSpan> GetTextAndHexSpans(bool isColumnPresent, HexCellCollection collection, HexBufferSpan span, HexSpanSelectionFlags flags, VST.Span visibleSpan, VST.Span fullSpan) { if (span.IsDefault) { throw new ArgumentException(); } if (span.Buffer != Buffer) { throw new ArgumentException(); } if (!isColumnPresent) { yield break; } var overlapSpan = BufferSpan.Overlap(span); if (overlapSpan == null) { yield break; } if ((flags & (HexSpanSelectionFlags.Group0 | HexSpanSelectionFlags.Group1)) != 0) { bool group0 = (flags & HexSpanSelectionFlags.Group0) != 0; bool group1 = (flags & HexSpanSelectionFlags.Group1) != 0; IEnumerable <HexCell> cells; if ((flags & HexSpanSelectionFlags.AllCells) != 0) { cells = collection.GetCells(); overlapSpan = BufferSpan; } else if ((flags & HexSpanSelectionFlags.AllVisibleCells) != 0) { cells = collection.GetVisibleCells(); overlapSpan = BufferSpan; } else { cells = collection.GetCells(overlapSpan.Value); } HexCell firstCell = null; HexCell lastCell = null; foreach (var cell in cells) { if (!((cell.GroupIndex == 0 && group0) || (cell.GroupIndex == 1 && group1))) { continue; } if (firstCell == null) { firstCell = cell; lastCell = cell; } else if (lastCell.Index + 1 == cell.Index && lastCell.GroupIndex == cell.GroupIndex) { lastCell = cell; } else { yield return(Create(collection, firstCell, lastCell, overlapSpan.Value)); firstCell = lastCell = cell; } } if (firstCell != null) { yield return(Create(collection, firstCell, lastCell, overlapSpan.Value)); } yield break; } if ((flags & HexSpanSelectionFlags.AllVisibleCells) != 0) { yield return(new TextAndHexSpan(visibleSpan, BufferSpan)); yield break; } if ((flags & HexSpanSelectionFlags.AllCells) != 0) { yield return(new TextAndHexSpan(fullSpan, BufferSpan)); yield break; } if ((flags & HexSpanSelectionFlags.OneValue) != 0) { foreach (var cell in collection.GetCells(overlapSpan.Value)) { if (!cell.HasData) { continue; } var cellSpan = cell.GetSpan(flags); yield return(new TextAndHexSpan(cellSpan, new HexBufferSpan(Buffer, cell.BufferSpan))); } } else { int textStart = int.MaxValue; int textEnd = int.MinValue; var posStart = HexPosition.MaxValue; var posEnd = HexPosition.MinValue; foreach (var cell in collection.GetCells(overlapSpan.Value)) { if (!cell.HasData) { continue; } var cellSpan = cell.GetSpan(flags); textStart = Math.Min(textStart, cellSpan.Start); textEnd = Math.Max(textEnd, cellSpan.End); posStart = HexPosition.Min(posStart, cell.BufferStart); posEnd = HexPosition.Max(posEnd, cell.BufferEnd); } if (textStart > textEnd || posStart > posEnd) { yield break; } yield return(new TextAndHexSpan(VST.Span.FromBounds(textStart, textEnd), new HexBufferSpan(Buffer, HexSpan.FromBounds(posStart, posEnd)))); } }
IEnumerable <TextAndHexSpan> GetTextAndHexSpans(bool isColumnPresent, HexCellCollection collection, HexBufferSpan span, HexSpanSelectionFlags flags, VST.Span visibleSpan, VST.Span fullSpan) { if (span.IsDefault) { throw new ArgumentException(); } if (span.Buffer != Buffer) { throw new ArgumentException(); } if (!isColumnPresent) { yield break; } var overlapSpan = BufferSpan.Overlap(span); if (overlapSpan is null) { yield break; } if ((flags & (HexSpanSelectionFlags.Group0 | HexSpanSelectionFlags.Group1)) != 0) { bool group0 = (flags & HexSpanSelectionFlags.Group0) != 0; bool group1 = (flags & HexSpanSelectionFlags.Group1) != 0; IEnumerable <HexCell> cells; if ((flags & HexSpanSelectionFlags.AllCells) != 0) { cells = collection.GetCells(); overlapSpan = BufferSpan; } else if ((flags & HexSpanSelectionFlags.AllVisibleCells) != 0) { cells = collection.GetVisibleCells(); overlapSpan = BufferSpan; } else { cells = collection.GetCells(overlapSpan.Value); } HexCell?firstCell = null; HexCell?lastCell = null; foreach (var cell in cells) { if (!((cell.GroupIndex == 0 && group0) || (cell.GroupIndex == 1 && group1))) { continue; } if (firstCell is null) { firstCell = cell; lastCell = cell; } else if (lastCell !.Index + 1 == cell.Index && lastCell.GroupIndex == cell.GroupIndex) { lastCell = cell; } else { yield return(Create(collection, firstCell, lastCell, overlapSpan.Value)); firstCell = lastCell = cell; } }