Skip to content

Commit d6a652b

Browse files
authored
Merge pull request #3783 from tig/v2_3777-hexedit
Fixes #3777 - `HexView` Focus Issue - Adds `View.AdvancingFocus` events
2 parents 0a108fa + 5c09fa2 commit d6a652b

22 files changed

+1071
-678
lines changed

Terminal.Gui/Application/Application.Run.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ public static RunState Begin (Toplevel toplevel)
8080
{
8181
ArgumentNullException.ThrowIfNull (toplevel);
8282

83-
#if DEBUG_IDISPOSABLE
84-
Debug.Assert (!toplevel.WasDisposed);
85-
86-
if (_cachedRunStateToplevel is { } && _cachedRunStateToplevel != toplevel)
87-
{
88-
Debug.Assert (_cachedRunStateToplevel.WasDisposed);
89-
}
90-
#endif
83+
//#if DEBUG_IDISPOSABLE
84+
// Debug.Assert (!toplevel.WasDisposed);
85+
86+
// if (_cachedRunStateToplevel is { } && _cachedRunStateToplevel != toplevel)
87+
// {
88+
// Debug.Assert (_cachedRunStateToplevel.WasDisposed);
89+
// }
90+
//#endif
9191

9292
// Ensure the mouse is ungrabbed.
9393
MouseGrabView = null;

Terminal.Gui/Application/ApplicationNavigation.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,19 @@ public ApplicationNavigation ()
2727
/// <summary>
2828
/// Gets the most focused <see cref="View"/> in the application, if there is one.
2929
/// </summary>
30-
public View? GetFocused () { return _focused; }
30+
public View? GetFocused ()
31+
{
32+
return _focused;
33+
34+
if (_focused is { CanFocus: true, HasFocus: true })
35+
{
36+
return _focused;
37+
}
38+
39+
_focused = null;
40+
41+
return null;
42+
}
3143

3244
/// <summary>
3345
/// Gets whether <paramref name="view"/> is in the Subview hierarchy of <paramref name="start"/>.
@@ -77,6 +89,7 @@ internal void SetFocused (View? value)
7789
{
7890
return;
7991
}
92+
Debug.Assert (value is null or { CanFocus: true, HasFocus: true });
8093

8194
_focused = value;
8295

Terminal.Gui/Drawing/Glyphs.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ public class GlyphDefinitions
9797
/// <summary>Dot. Default is (U+2219) - ∙.</summary>
9898
public Rune Dot { get; set; } = (Rune)'∙';
9999

100+
/// <summary>Dotted Square - ⬚ U+02b1a┝</summary>
101+
public Rune DottedSquare { get; set; } = (Rune)'⬚';
102+
100103
/// <summary>Black Circle . Default is (U+025cf) - ●.</summary>
101104
public Rune BlackCircle { get; set; } = (Rune)'●'; // Black Circle - ● U+025cf
102105

Terminal.Gui/Input/Command.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ public enum Command
166166
/// </summary>
167167
EnableOverwrite,
168168

169+
/// <summary>
170+
/// Inserts a character.
171+
/// </summary>
172+
Insert,
173+
169174
/// <summary>Disables overwrite mode (<see cref="EnableOverwrite"/>)</summary>
170175
DisableOverwrite,
171176

Terminal.Gui/View/Adornment/ShadowView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private void DrawHorizontalShadowTransparent (Rectangle viewport)
109109
Rectangle screen = ViewportToScreen (viewport);
110110

111111
// Fill the rest of the rectangle - note we skip the last since vertical will draw it
112-
for (int i = screen.X + 1; i < screen.X + screen.Width - 1; i++)
112+
for (int i = Math.Max(0, screen.X + 1); i < screen.X + screen.Width - 1; i++)
113113
{
114114
Driver.Move (i, screen.Y);
115115

Terminal.Gui/View/CancelEventArgs.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ public CancelEventArgs (ref readonly T currentValue, ref T newValue, bool cancel
2727
NewValue = newValue;
2828
}
2929

30+
/// <summary>
31+
/// Initializes a new instance of the <see cref="CancelEventArgs{T}"/> class.
32+
/// </summary>
33+
/// <param name="currentValue">The current (old) value of the property.</param>
34+
/// <param name="newValue">The value the property will be set to if the event is not cancelled.</param>
35+
protected CancelEventArgs (T currentValue, T newValue)
36+
{
37+
CurrentValue = currentValue;
38+
NewValue = newValue;
39+
}
40+
3041
/// <summary>The current value of the property.</summary>
3142
public T CurrentValue { get; }
3243

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Terminal.Gui;
2+
3+
/// <summary>The event arguments for <see cref="View.AdvanceFocus"/> events.</summary>
4+
public class AdvanceFocusEventArgs : CancelEventArgs<bool>
5+
{
6+
/// <summary>Initializes a new instance.</summary>
7+
public AdvanceFocusEventArgs (NavigationDirection direction, TabBehavior? behavior) : base (false, false)
8+
{
9+
Direction = direction;
10+
Behavior = behavior;
11+
}
12+
13+
/// <summary>Gets or sets the view that is losing focus.</summary>
14+
public NavigationDirection Direction { get; set; }
15+
16+
/// <summary>Gets or sets the view that is gaining focus.</summary>
17+
public TabBehavior? Behavior { get; set; }
18+
}

Terminal.Gui/View/Navigation/FocusEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ public HasFocusEventArgs (bool currentHasFocus, bool newHasFocus, View currentFo
2020
/// <summary>Gets or sets the view that is gaining focus.</summary>
2121
public View NewFocused { get; set; }
2222

23-
}
23+
}

Terminal.Gui/View/View.Hierarchy.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ public virtual void OnRemoved (SuperViewChangedEventArgs e)
169169
Debug.Assert (!view.HasFocus);
170170

171171
_subviews.Remove (view);
172+
173+
// Clean up focus stuff
174+
_previouslyFocused = null;
175+
if (view._superView is { } && view._superView._previouslyFocused == this)
176+
{
177+
view._superView._previouslyFocused = null;
178+
}
172179
view._superView = null;
173180

174181
SetNeedsLayout ();

0 commit comments

Comments
 (0)