From 373fe4441e9e665ba3b6fadfded8f38053fe0cce Mon Sep 17 00:00:00 2001 From: Washi Date: Fri, 13 Dec 2024 22:39:38 +0100 Subject: [PATCH] BUGFIX: Always render full line range and allow to move to the virtual cell --- src/AvaloniaHex/Editing/Caret.cs | 10 ++++------ src/AvaloniaHex/Rendering/CellBasedColumn.cs | 7 +++++++ src/AvaloniaHex/Rendering/HexView.cs | 6 +++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/AvaloniaHex/Editing/Caret.cs b/src/AvaloniaHex/Editing/Caret.cs index d1f39fd..a8fbc42 100644 --- a/src/AvaloniaHex/Editing/Caret.cs +++ b/src/AvaloniaHex/Editing/Caret.cs @@ -152,7 +152,7 @@ public void GoToEndOfDocument() if (PrimaryColumn is not { } primaryColumn) return; - Location = primaryColumn.GetLastLocation(Mode == EditingMode.Insert); + Location = primaryColumn.GetLastLocation(true); } /// @@ -225,7 +225,7 @@ public void GoBackward(ulong byteCount) public void GoRight() { if (PrimaryColumn is { } column) - Location = column.GetNextLocation(Location, Mode == EditingMode.Insert, true); + Location = column.GetNextLocation(Location, true, true); } /// @@ -249,12 +249,10 @@ public void GoForward(ulong byteCount) // Note: We cannot use BitLocation.Clamp due to unsigned overflow that may happen. - ulong effectiveDocumentLength = document.Length - (Mode == EditingMode.Insert ? 0u : 1u); - if (document.Length < byteCount - || Location.ByteIndex >= effectiveDocumentLength - byteCount) + || Location.ByteIndex >= document.Length - byteCount) { - Location = new BitLocation(effectiveDocumentLength, PrimaryColumn.FirstBitIndex); + Location = new BitLocation(document.Length, PrimaryColumn.FirstBitIndex); return; } diff --git a/src/AvaloniaHex/Rendering/CellBasedColumn.cs b/src/AvaloniaHex/Rendering/CellBasedColumn.cs index d8a9ffb..045850c 100644 --- a/src/AvaloniaHex/Rendering/CellBasedColumn.cs +++ b/src/AvaloniaHex/Rendering/CellBasedColumn.cs @@ -278,6 +278,11 @@ public Rect GetRelativeGroupBounds(VisualBytesLine line, BitLocation location) ); } + /// + /// Aligns the provided location to the beginning of the cell that contains the location. + /// + /// The location to align. + /// The aligned location. public BitLocation AlignToCell(BitLocation location) { return new BitLocation(location.ByteIndex, location.BitIndex / BitsPerCell * BitsPerCell); @@ -325,6 +330,8 @@ public BitLocation GetPreviousLocation(BitLocation location) /// Given a bit location, gets the location of the cell after it. /// /// The location. + /// true if the virtual cell at the end of the document should be included. + /// true if the location should be restricted to the current document length. /// The next cell's location. public BitLocation GetNextLocation(BitLocation location, bool includeVirtualCell, bool clamp) { diff --git a/src/AvaloniaHex/Rendering/HexView.cs b/src/AvaloniaHex/Rendering/HexView.cs index a49c9fa..ab7659d 100644 --- a/src/AvaloniaHex/Rendering/HexView.cs +++ b/src/AvaloniaHex/Rendering/HexView.cs @@ -496,18 +496,18 @@ private VisualBytesLine GetOrCreateVisualLine(BitRange range) { // Exact match? var currentLine = _visualLines[i]; - if (currentLine.VirtualRange.Start == range.Start) + if (currentLine.Range.Start == range.Start) { // Edge-case: if our range is not exactly right, the line's range is outdated (e.g., as a result of // inserting or removing a character at the end of the document). - if (currentLine.VirtualRange.End != range.End) + if (currentLine.Range.End != range.End) _visualLines[i] = currentLine = new VisualBytesLine(this, range, Columns.Count); return currentLine; } // If the next line is further than the requested start, the line does not exist. - if (currentLine.VirtualRange.Start > range.Start) + if (currentLine.Range.Start > range.Start) { newLine = new VisualBytesLine(this, range, Columns.Count); _visualLines.Insert(i, newLine);