Skip to content

Commit 81b7cd4

Browse files
committed
enhance: make sure highlighted index is less than the file size
Signed-off-by: leo <longshuang@msn.cn>
1 parent 56424e5 commit 81b7cd4

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎src/Views/BinaryFileViewer.axaml.cs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Globalization;
33
using System.Threading;
4+
45
using Avalonia;
56
using Avalonia.Controls;
67
using Avalonia.Controls.Primitives;
@@ -179,6 +180,9 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)
179180
{
180181
base.OnPointerPressed(e);
181182

183+
if (DataContext is not ViewModels.BinaryFile vm)
184+
return;
185+
182186
var pos = e.GetPosition(this);
183187
var testX = pos.X;
184188
var testY = pos.Y - HEADER_HEIGHT;
@@ -210,7 +214,11 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)
210214
return;
211215

212216
var rowIdx = (long)Math.Floor(testY / LINE_HEIGHT);
213-
SetHighlightedIndex(_offset + rowIdx * BYTES_PER_LINE + columnIdx);
217+
var idx = _offset + rowIdx * BYTES_PER_LINE + columnIdx;
218+
if (idx >= vm.FileSize)
219+
return;
220+
221+
SetHighlightedIndex(idx);
214222
}
215223

216224
private void SetHighlightedIndex(long idx)
@@ -241,6 +249,8 @@ protected override void OnUnloaded(RoutedEventArgs e)
241249
{
242250
base.OnUnloaded(e);
243251

252+
_cancellation?.Cancel();
253+
244254
if (Content is ViewModels.BinaryFile old)
245255
{
246256
Content = null;

0 commit comments

Comments
 (0)