diff --git a/src/Gen3Hex.Core/ViewModels/ViewPort.cs b/src/Gen3Hex.Core/ViewModels/ViewPort.cs index a1f69b62..a0d51d78 100644 --- a/src/Gen3Hex.Core/ViewModels/ViewPort.cs +++ b/src/Gen3Hex.Core/ViewModels/ViewPort.cs @@ -111,16 +111,7 @@ namespace HavenSoft.Gen3Hex.Core.ViewModels { private void ClearActiveEditBeforeSelectionChanges(object sender, Point location) { if (location.X >= 0 && location.X < scroll.Width && location.Y >= 0 && location.Y < scroll.Height) { - var element = currentView[location.X, location.Y]; - if (element.Format is UnderEdit underEdit) { - if (underEdit.CurrentText.StartsWith(AnchorStart.ToString())) { - currentView[location.X, location.Y] = new HexElement(element.Value, underEdit.Edit(" ")); - if (!TryCompleteEdit(location)) ClearEdits(location); - } else { - currentView[location.X, location.Y] = new HexElement(element.Value, underEdit.OriginalFormat); - NotifyCollectionChanged(ResetArgs); - } - } + ClearEdits(location); } } diff --git a/src/Gen3Hex.Tests/PointerModelTests.cs b/src/Gen3Hex.Tests/PointerModelTests.cs index 97537cba..c4520076 100644 --- a/src/Gen3Hex.Tests/PointerModelTests.cs +++ b/src/Gen3Hex.Tests/PointerModelTests.cs @@ -518,7 +518,7 @@ namespace HavenSoft.Gen3Hex.Tests { } [Fact] - public void ArrowMovementWhileTypingAnchorInsertsAnchor() { + public void ArrowMovementWhileTypingAnchorRevertsChange() { var buffer = Enumerable.Repeat((byte)0xFF, 0x200).ToArray(); var model = new PokemonModel(buffer); var viewPort = new ViewPort(new LoadedFile("test.txt", buffer), model) { Width = 0x10, Height = 0x10 }; @@ -527,8 +527,7 @@ namespace HavenSoft.Gen3Hex.Tests { viewPort.SelectionStart = new Point(1, 1); - var format = viewPort[0, 0].Format; - Assert.IsType(format); + Assert.IsType(viewPort[0, 0].Format); } [Fact] @@ -680,5 +679,21 @@ namespace HavenSoft.Gen3Hex.Tests { Assert.Equal(0x100, ((Pointer)viewPort[0, 0].Format).Destination); } + + [Fact] + public void StartingPointerEditAndThenMovingClearsAllEditedCells() { + var data = new byte[0x200]; + var model = new PokemonModel(data); + var viewPort = new ViewPort(new LoadedFile("test.txt", data), model) { Width = 0x10, Height = 0x10 }; + + viewPort.Edit("<"); + viewPort.SelectionStart = new Point(2, 2); + + for (int x = 0; x < 0x10; x++) { + for (int y = 0; y < 0x10; y++) { + Assert.IsNotType(viewPort[x, y].Format); + } + } + } } } diff --git a/src/Gen3Hex.WPF/Controls/HexContent.cs b/src/Gen3Hex.WPF/Controls/HexContent.cs index f83ba7e9..c8c14d60 100644 --- a/src/Gen3Hex.WPF/Controls/HexContent.cs +++ b/src/Gen3Hex.WPF/Controls/HexContent.cs @@ -214,13 +214,12 @@ namespace HavenSoft.Gen3Hex.WPF.Controls { if (ViewPort == null) return; drawingContext.DrawRectangle(Solarized.Theme.Background, null, new Rect(0, 0, ActualWidth, ActualHeight)); - var visitor = new FormatDrawer(drawingContext); + var visitor = new FormatDrawer(drawingContext, ViewPort.Width, ViewPort.Height); var topLeft = new ScreenPoint(0, 0); var topRight = new ScreenPoint(CellWidth, 0); var bottomLeft = new ScreenPoint(0, CellHeight); var bottomRight = new ScreenPoint(CellWidth, CellHeight); - var rectangleGeometry = new RectangleGeometry(new Rect(topLeft, bottomRight)); var borderPen = new Pen(Solarized.Brushes.Green, 1); // draw matrix @@ -256,10 +255,9 @@ namespace HavenSoft.Gen3Hex.WPF.Controls { visitor.MouseIsOverCurrentFormat = mouseOverPoint.Equals(new ModelPoint(x, y)); var element = ViewPort[x, y]; drawingContext.PushTransform(new TranslateTransform(x * CellWidth, y * CellHeight)); - drawingContext.PushClip(rectangleGeometry); + visitor.Position = new ModelPoint(x, y); element.Format.Visit(visitor, element.Value); drawingContext.Pop(); - drawingContext.Pop(); } } } diff --git a/src/Gen3Hex.WPF/Implementations/FormatDrawer.cs b/src/Gen3Hex.WPF/Implementations/FormatDrawer.cs index 6f607ca3..10636818 100644 --- a/src/Gen3Hex.WPF/Implementations/FormatDrawer.cs +++ b/src/Gen3Hex.WPF/Implementations/FormatDrawer.cs @@ -14,11 +14,16 @@ namespace HavenSoft.Gen3Hex.WPF.Implementations { private static readonly List noneVisualCache = new List(); + private readonly int modelWidth, modelHeight; + private readonly DrawingContext context; + private readonly Geometry rectangleGeometry = new RectangleGeometry(new Rect(new Point(0, 0), new Point(HexContent.CellWidth, HexContent.CellHeight))); public bool MouseIsOverCurrentFormat { get; set; } - public FormatDrawer(DrawingContext drawingContext) => context = drawingContext; + public HavenSoft.Gen3Hex.Core.Models.Point Position { get; set; } + + public FormatDrawer(DrawingContext drawingContext, int width, int height) => (context, modelWidth, modelHeight) = (drawingContext, width, height); public static void ClearVisualCaches() { noneVisualCache.Clear(); @@ -72,7 +77,13 @@ namespace HavenSoft.Gen3Hex.WPF.Implementations { brush, 1.0); - context.DrawText(text, new Point(CellTextOffset.X + xOffset, CellTextOffset.Y)); + if (dataFormat.Position < Position.X || Position.X - dataFormat.Position > modelWidth - 4) { + context.PushClip(rectangleGeometry); + context.DrawText(text, new Point(CellTextOffset.X + xOffset, CellTextOffset.Y)); + context.Pop(); + } else if (dataFormat.Position == 2) { + context.DrawText(text, new Point(CellTextOffset.X + xOffset, CellTextOffset.Y)); + } } private static readonly Geometry Triangle = Geometry.Parse("M0,5 L3,0 6,5");