Переглянути джерело

Removed restriction in View.Move

Tig 8 місяців тому
батько
коміт
245d78e952

+ 0 - 8
Terminal.Gui/View/View.Drawing.Primitives.cs

@@ -7,9 +7,6 @@ public partial class View
     /// <summary>Moves the drawing cursor to the specified <see cref="Viewport"/>-relative location in the view.</summary>
     /// <remarks>
     ///     <para>
-    ///         If the provided coordinates are outside the visible content area, this method does nothing.
-    ///     </para>
-    ///     <para>
     ///         The top-left corner of the visible content area is <c>ViewPort.Location</c>.
     ///     </para>
     /// </remarks>
@@ -22,11 +19,6 @@ public partial class View
             return false;
         }
 
-        if (col < 0 || row < 0 || col >= Viewport.Width || row >= Viewport.Height)
-        {
-            return false;
-        }
-
         Point screen = ViewportToScreen (new Point (col, row));
         Driver?.Move (screen.X, screen.Y);
 

+ 33 - 22
Terminal.Gui/Views/HexView.cs

@@ -109,7 +109,7 @@ public class HexView : View, IDesignable
     private void HexViewSubviewsLaidOut (object? sender, LayoutEventArgs e)
     {
         SetBytesPerLine ();
-        SetContentSize (new (GetLeftSideStartColumn () + BytesPerLine / NUM_BYTES_PER_HEX_COLUMN * HEX_COLUMN_WIDTH, (int)((GetEditedSize ()) / BytesPerLine) + 1));
+        SetContentSize (new (GetLeftSideStartColumn () + BytesPerLine / NUM_BYTES_PER_HEX_COLUMN * HEX_COLUMN_WIDTH + BytesPerLine - 1, (int)((GetEditedSize ()) / BytesPerLine) + 1));
     }
 
     /// <summary>Initializes a <see cref="HexView"/> class.</summary>
@@ -142,6 +142,19 @@ public class HexView : View, IDesignable
     public Point GetCursor (long address)
     {
         Point position = GetPosition (address);
+        if (_leftSideHasFocus)
+        {
+            int block = position.X / NUM_BYTES_PER_HEX_COLUMN;
+            int column = position.X % NUM_BYTES_PER_HEX_COLUMN;
+
+            position.X = block * HEX_COLUMN_WIDTH + column * 3 + (_firstNibble ? 0 : 1);
+        }
+        else
+        {
+            position.X += BytesPerLine / NUM_BYTES_PER_HEX_COLUMN * HEX_COLUMN_WIDTH - 1;
+        }
+        position.X += GetLeftSideStartColumn ();
+
         position.Offset (-Viewport.X, -Viewport.Y);
         return position;
     }
@@ -149,7 +162,7 @@ public class HexView : View, IDesignable
     private void ScrollToMakeCursorVisible (Point offsetToNewCursor)
     {
         // Adjust vertical scrolling
-        if (offsetToNewCursor.Y < 1) // Header is at Y = 0
+        if (offsetToNewCursor.Y < 1)
         {
             ScrollVertical (offsetToNewCursor.Y);
         }
@@ -157,33 +170,31 @@ public class HexView : View, IDesignable
         {
             ScrollVertical (offsetToNewCursor.Y);
         }
-    }
 
+        if (offsetToNewCursor.X < 1)
+        {
+            ScrollHorizontal(offsetToNewCursor.X);
+        }
+        else if (offsetToNewCursor.X >= Viewport.Width)
+        {
+            ScrollHorizontal (offsetToNewCursor.X);
+        }
+    }
 
     ///<inheritdoc/>
     public override Point? PositionCursor ()
     {
         Point position = GetCursor (Address);
 
-        int block = position.X / NUM_BYTES_PER_HEX_COLUMN;
-        int column = position.X % NUM_BYTES_PER_HEX_COLUMN * 3;
-
-        int x = GetLeftSideStartColumn () + block * HEX_COLUMN_WIDTH + column + (_firstNibble ? 0 : 1);
-        int y = position.Y;
-
-        if (!_leftSideHasFocus)
-        {
-            x = GetLeftSideStartColumn () + BytesPerLine / NUM_BYTES_PER_HEX_COLUMN * HEX_COLUMN_WIDTH + position.X - 1;
-        }
-
         if (HasFocus
-            && x >= 0
-            && x < Viewport.Width - AddressWidth + 1
-            && y >= 0
-            && y < Viewport.Height)
+            && position.X >= 0
+            && position.X < Viewport.Width
+            && position.Y >= 0
+            && position.Y < Viewport.Height)
         {
-            Move (x, y);
-            return new (x, y);
+            Move (position.X, position.Y);
+
+            return position;
         }
         return null;
     }
@@ -438,7 +449,7 @@ public class HexView : View, IDesignable
         Attribute currentAttribute = Attribute.Default;
         Attribute current = GetFocusColor ();
         SetAttribute (current);
-        Move (0, 0);
+        Move (-Viewport.X, 0);
 
         long addressOfFirstLine = Viewport.Y * BytesPerLine;
 
@@ -453,7 +464,7 @@ public class HexView : View, IDesignable
         Attribute addressAttribute = new Attribute (GetNormalColor ().Foreground.GetHighlightColor (), GetNormalColor ().Background);
         for (var line = 0; line < Viewport.Height; line++)
         {
-            Move (0, line);
+            Move (-Viewport.X, line);
             long addressOfLine = addressOfFirstLine + line * nBlocks * NUM_BYTES_PER_HEX_COLUMN;
 
             if (addressOfLine <= GetEditedSize ())

+ 1 - 0
UICatalog/Scenarios/HexEditor.cs

@@ -149,6 +149,7 @@ public class HexEditor : Scenario
         app.Add (_statusBar);
 
         _hexView.VerticalScrollBar.AutoShow = true;
+        _hexView.HorizontalScrollBar.AutoShow = true;
 
         _hexView.Source = LoadFile ();
 

+ 3 - 5
UnitTests/View/Draw/DrawTests.cs

@@ -10,7 +10,7 @@ public class DrawTests (ITestOutputHelper _output)
 
     [Fact]
     [SetupFakeDriver]
-    public void Move_Is_Constrained_To_Viewport ()
+    public void Move_Is_Not_Constrained_To_Viewport ()
     {
         var view = new View
         {
@@ -20,16 +20,14 @@ public class DrawTests (ITestOutputHelper _output)
         };
         view.Margin!.Thickness = new (1);
 
-        // Only valid location w/in Viewport is 0, 0 (view) - 2, 2 (screen)
-
         view.Move (0, 0);
         Assert.Equal (new (2, 2), new Point (Application.Driver!.Col, Application.Driver!.Row));
 
         view.Move (-1, -1);
-        Assert.Equal (new (2, 2), new Point (Application.Driver!.Col, Application.Driver!.Row));
+        Assert.Equal (new (1, 1), new Point (Application.Driver!.Col, Application.Driver!.Row));
 
         view.Move (1, 1);
-        Assert.Equal (new (2, 2), new Point (Application.Driver!.Col, Application.Driver!.Row));
+        Assert.Equal (new (3, 3), new Point (Application.Driver!.Col, Application.Driver!.Row));
     }
 
     [Fact]