瀏覽代碼

working on cursor issue

Tig 1 年之前
父節點
當前提交
3406d97c4c

+ 25 - 23
Terminal.Gui/View/ViewSubViews.cs

@@ -851,35 +851,37 @@ public partial class View
         return view.Focused is { } ? GetMostFocused (view.Focused) : view;
     }
 
-    /// <summary>Positions the cursor in the right position based on the currently focused view in the chain.</summary>
-    /// Views that are focusable should override
-    /// <see cref="PositionCursor"/>
-    /// to ensure
-    /// the cursor is placed in a location that makes sense. Unix terminals do not have
+    /// <summary>
+    ///     Positions the cursor in the right position based on the currently focused view in the chain.
+    /// </summary>
+    /// <remarks>
+    /// Views that are focusable and want the cursor visible should override <see cref="PositionCursor"/> 
+    /// place the cursor in a location that makes sense. Unix terminals do not have
     /// a way of hiding the cursor, so it can be distracting to have the cursor left at
     /// the last focused view. Views should make sure that they place the cursor
     /// in a visually sensible place.
+    /// </remarks>
     /// <returns>Viewport-relative cursor position.</returns>
     public virtual Point? PositionCursor ()
     {
-        if (!IsInitialized)
-        {
-            return null;
-        }
-
-        // TODO: v2 - This needs to support Subviews of Adornments too
-
-        // By default we will position the cursor at the top left corner of the Viewport.
-        // Overrides should return the position where the cursor has been placed.
-        Point location = Viewport.Location;
-
-        if (CanFocus && HasFocus && ContentSize != Size.Empty)
-        {
-            location.X = TextFormatter.HotKeyPos == -1 ? 0 : TextFormatter.CursorPosition;
-            location.Y = 0;
-            Move (location.X, location.Y);
-            return location;
-        }
+        //if (!IsInitialized)
+        //{
+        //    return null;
+        //}
+
+        //// TODO: v2 - This needs to support Subviews of Adornments too
+
+        //// By default we will position the cursor at the top left corner of the Viewport.
+        //// Overrides should return the position where the cursor has been placed.
+        //Point location = Viewport.Location;
+
+        //if (CanFocus && HasFocus && ContentSize != Size.Empty)
+        //{
+        //    location.X = TextFormatter.HotKeyPos == -1 ? 0 : TextFormatter.CursorPosition;
+        //    location.Y = 0;
+        //    Move (location.X, location.Y);
+        //    return location;
+        //}
 
         return null;
 

+ 7 - 7
Terminal.Gui/Views/Button.cs

@@ -137,13 +137,13 @@ public class Button : View
     /// <summary></summary>
     public bool NoPadding { get; set; }
 
-    /// <inheritdoc/>
-    public override bool OnEnter (View view)
-    {
-        Application.Driver.SetCursorVisibility (CursorVisibility.Invisible);
+    ///// <inheritdoc/>
+    //public override bool OnEnter (View view)
+    //{
+    //    Application.Driver.SetCursorVisibility (CursorVisibility.Invisible);
 
-        return base.OnEnter (view);
-    }
+    //    return base.OnEnter (view);
+    //}
 
     /// <inheritdoc/>
     public override Point? PositionCursor ()
@@ -156,7 +156,7 @@ public class Button : View
                 {
                     Move (i, 0);
 
-                    return new (i,0);
+                    return null;//new (i,0);
                 }
             }
         }

+ 6 - 5
Terminal.Gui/Views/ListView.cs

@@ -700,10 +700,10 @@ public class ListView : View
     /// <inheritdoc/>
     public override bool OnEnter (View view)
     {
-        if (IsInitialized)
-        {
-            Application.Driver.SetCursorVisibility (CursorVisibility.Invisible);
-        }
+        //if (IsInitialized)
+        //{
+        //    Application.Driver.SetCursorVisibility (CursorVisibility.Invisible);
+        //}
 
         if (_lastSelectedItem != _selected)
         {
@@ -791,7 +791,8 @@ public class ListView : View
         }
 
         Move (x, y);
-        return new Point (x, y);
+
+        return null;//new Point (x, y);
     }
 
     /// <summary>This event is invoked when this <see cref="ListView"/> is being drawn before rendering.</summary>

+ 3 - 2
Terminal.Gui/Views/Menu/Menu.cs

@@ -935,7 +935,7 @@ internal sealed class Menu : View
 
         Driver.Clip = savedClip;
 
-        PositionCursor ();
+       // PositionCursor ();
     }
 
     private void Current_DrawContentComplete (object sender, DrawEventArgs e)
@@ -957,7 +957,8 @@ internal sealed class Menu : View
             else
             {
                 Move (2, 1 + _currentChild);
-                return new (2, 1 + _currentChild);
+
+                return null;//new (2, 1 + _currentChild);
             }
         }
 

+ 2 - 2
Terminal.Gui/Views/Menu/MenuBar.cs

@@ -509,7 +509,7 @@ public class MenuBar : View
                    + _rightPadding;
         }
 
-        PositionCursor ();
+        //PositionCursor ();
     }
 
     /// <summary>Virtual method that will invoke the <see cref="MenuAllClosed"/>.</summary>
@@ -788,7 +788,7 @@ public class MenuBar : View
                 else
                 {
                     SetFocus ();
-                    PositionCursor ();
+                    //PositionCursor ();
                 }
 
                 IsMenuOpen = false;

+ 2 - 1
Terminal.Gui/Views/ScrollView.cs

@@ -460,7 +460,8 @@ public class ScrollView : View
         if (InternalSubviews.Count == 0)
         {
             Move (0, 0);
-            return Point.Empty;
+
+            return null;//Point.Empty;
         }
         return base.PositionCursor ();
     }

+ 1 - 1
Terminal.Gui/Views/Slider.cs

@@ -316,7 +316,7 @@ public class Slider<T> : View
         {
             _lastFocusedOption = FocusedOption;
             FocusedOption = newFocusedOption;
-            PositionCursor ();
+            //PositionCursor ();
         }
 
         return args.Cancel;

+ 4 - 3
Terminal.Gui/Views/TableView/TableView.cs

@@ -978,7 +978,7 @@ public class TableView : View
     {
         if (TableIsNullOrInvisible ())
         {
-            PositionCursor ();
+            //PositionCursor ();
 
             return false;
         }
@@ -1029,7 +1029,8 @@ public class TableView : View
         if (screenPoint is { })
         {
             Move (screenPoint.Value.X, screenPoint.Value.Y);
-            return screenPoint;
+
+            return null;//screenPoint;
         }
 
         return null;
@@ -1529,7 +1530,7 @@ public class TableView : View
             SelectedRow = match;
             EnsureValidSelection ();
             EnsureSelectedCellIsVisible ();
-            PositionCursor ();
+            //PositionCursor ();
             SetNeedsDisplay ();
 
             return true;

+ 2 - 2
Terminal.Gui/Views/TextField.cs

@@ -1026,7 +1026,7 @@ public class TextField : View
             Driver.AddRune ((Rune)' ');
         }
 
-        PositionCursor ();
+        //PositionCursor ();
 
         RenderCaption ();
 
@@ -1269,7 +1269,7 @@ public class TextField : View
         }
         else
         {
-            PositionCursor ();
+            //PositionCursor ();
         }
     }
 

+ 16 - 16
Terminal.Gui/Views/TextView.cs

@@ -3228,7 +3228,7 @@ public class TextView : View
             }
             else
             {
-                PositionCursor ();
+                //PositionCursor ();
             }
         }
     }
@@ -3353,7 +3353,7 @@ public class TextView : View
 
             if (Used)
             {
-                PositionCursor ();
+                //PositionCursor ();
             }
             else
             {
@@ -3390,7 +3390,7 @@ public class TextView : View
         else if (ev.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition))
         {
             ProcessMouseClick (ev, out List<RuneCell> line);
-            PositionCursor ();
+            //PositionCursor ();
 
             if (_model.Count > 0 && _shiftSelecting && Selecting)
             {
@@ -3441,7 +3441,7 @@ public class TextView : View
             }
 
             ProcessMouseClick (ev, out _);
-            PositionCursor ();
+            //PositionCursor ();
             _lastWasKill = false;
             _columnTrack = CurrentColumn;
         }
@@ -3454,7 +3454,7 @@ public class TextView : View
             }
 
             ProcessMouseClick (ev, out _);
-            PositionCursor ();
+           // PositionCursor ();
 
             if (!Selecting)
             {
@@ -3514,7 +3514,7 @@ public class TextView : View
                 CurrentColumn = CurrentRow == newPos.Value.row ? newPos.Value.col : line.Count;
             }
 
-            PositionCursor ();
+           // PositionCursor ();
             _lastWasKill = false;
             _columnTrack = CurrentColumn;
         }
@@ -3534,7 +3534,7 @@ public class TextView : View
             }
 
             CurrentColumn = line.Count;
-            PositionCursor ();
+            //PositionCursor ();
             _lastWasKill = false;
             _columnTrack = CurrentColumn;
         }
@@ -3554,7 +3554,7 @@ public class TextView : View
         List<RuneCell> line = GetCurrentLine ();
         CurrentColumn = line.Count;
         TrackColumn ();
-        PositionCursor ();
+        //PositionCursor ();
     }
 
     /// <summary>Will scroll the <see cref="TextView"/> to the first line and position the cursor there.</summary>
@@ -3565,7 +3565,7 @@ public class TextView : View
         CurrentColumn = 0;
         _leftColumn = 0;
         TrackColumn ();
-        PositionCursor ();
+        //PositionCursor ();
         SetNeedsDisplay ();
     }
 
@@ -3671,7 +3671,7 @@ public class TextView : View
             ClearRegion (viewport.Left, row, right, bottom);
         }
 
-        PositionCursor ();
+        //PositionCursor ();
 
         _isDrawing = false;
     }
@@ -4174,7 +4174,7 @@ public class TextView : View
         }
         else
         {
-            PositionCursor ();
+            //PositionCursor ();
         }
 
         OnUnwrappedCursorPosition ();
@@ -4525,7 +4525,7 @@ public class TextView : View
         }
         else
         {
-            PositionCursor ();
+            //PositionCursor ();
         }
     }
 
@@ -5357,7 +5357,7 @@ public class TextView : View
             }
 
             TrackColumn ();
-            PositionCursor ();
+            //PositionCursor ();
         }
         else if (CurrentRow > Frame.Height)
         {
@@ -5436,7 +5436,7 @@ public class TextView : View
             }
 
             TrackColumn ();
-            PositionCursor ();
+            //PositionCursor ();
         }
 
         DoNeededAction ();
@@ -5462,7 +5462,7 @@ public class TextView : View
             }
 
             TrackColumn ();
-            PositionCursor ();
+           // PositionCursor ();
         }
 
         DoNeededAction ();
@@ -5555,7 +5555,7 @@ public class TextView : View
             }
 
             TrackColumn ();
-            PositionCursor ();
+            //PositionCursor ();
         }
 
         DoNeededAction ();

+ 2 - 1
Terminal.Gui/Views/TileView.cs

@@ -993,7 +993,8 @@ public class TileView : View
 
             Point location = moveRuneRenderLocation ?? new Point (Viewport.Width / 2, Viewport.Height / 2);
             Move (location.X, location.Y);
-            return location;
+
+            return null; //location;
         }
 
         /// <summary>

+ 2 - 1
Terminal.Gui/Views/Toplevel.cs

@@ -372,7 +372,8 @@ public partial class Toplevel : View
         {
             Driver.SetCursorVisibility (CursorVisibility.Invisible);
         }
-        return cursor2;
+
+        return null;//cursor2;
     }
 
     /// <summary>

+ 2 - 1
Terminal.Gui/Views/TreeView/TreeView.cs

@@ -1250,7 +1250,8 @@ public class TreeView<T> : View, ITreeView where T : class
             if (idx - ScrollOffsetVertical >= 0 && idx - ScrollOffsetVertical < Viewport.Height)
             {
                 Move (0, idx - ScrollOffsetVertical);
-                return new Point (0, idx - ScrollOffsetVertical);
+
+                return null;//new Point (0, idx - ScrollOffsetVertical);
             }
         }
         return base.PositionCursor ();

+ 3 - 19
UICatalog/Scenarios/CharacterMap.cs

@@ -315,7 +315,6 @@ public class CharacterMap : Scenario
 
 internal class CharMap : View
 {
-    private const CursorVisibility _cursor = CursorVisibility.Default;
     private const int COLUMN_WIDTH = 3;
 
     private ContextMenu _contextMenu = new ();
@@ -803,23 +802,6 @@ internal class CharMap : View
         }
     }
 
-    public override bool OnEnter (View view)
-    {
-        if (IsInitialized)
-        {
-            Application.Driver.SetCursorVisibility (_cursor);
-        }
-
-        return base.OnEnter (view);
-    }
-
-    public override bool OnLeave (View view)
-    {
-        Driver.SetCursorVisibility (CursorVisibility.Invisible);
-
-        return base.OnLeave (view);
-    }
-
     public override Point? PositionCursor ()
     {
         if (HasFocus
@@ -828,12 +810,14 @@ internal class CharMap : View
             && Cursor.Y > 0
             && Cursor.Y < Viewport.Height)
         {
-            Driver.SetCursorVisibility (_cursor);
+            Driver.SetCursorVisibility (CursorVisibility.Default);
             Move (Cursor.X, Cursor.Y);
         }
         else
         {
             Driver.SetCursorVisibility (CursorVisibility.Invisible);
+
+            return null;
         }
 
         return Cursor;