Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Terminal.Gui/Core/Toplevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,9 @@ internal View EnsureVisibleBounds (Toplevel top, int x, int y,
}
nx = Math.Max (x, 0);
nx = nx + top.Frame.Width > l ? Math.Max (l - top.Frame.Width, 0) : nx;
if (nx + (top.Border != null && top.Border.DrawMarginFrame ? 2 : 1) > top.Frame.X + top.Frame.Width) {
nx = Math.Max (top.Frame.Right - (top.Border.DrawMarginFrame ? 2 : 1), 0);
var mfLength = top.Border?.DrawMarginFrame == true ? 2 : 1;
if (nx + mfLength > top.Frame.X + top.Frame.Width) {
nx = Math.Max (top.Frame.Right - mfLength, 0);
}
//System.Diagnostics.Debug.WriteLine ($"nx:{nx}, rWidth:{rWidth}");
bool m, s;
Expand Down Expand Up @@ -653,8 +654,8 @@ internal View EnsureVisibleBounds (Toplevel top, int x, int y,
}
ny = Math.Min (ny, l);
ny = ny + top.Frame.Height >= l ? Math.Max (l - top.Frame.Height, m ? 1 : 0) : ny;
if (ny + (top.Border != null && top.Border.DrawMarginFrame ? 2 : 1) > top.Frame.Y + top.Frame.Height) {
ny = Math.Max (top.Frame.Bottom - (top.Border.DrawMarginFrame ? 2 : 1), 0);
if (ny + mfLength > top.Frame.Y + top.Frame.Height) {
ny = Math.Max (top.Frame.Bottom - mfLength, 0);
}
//System.Diagnostics.Debug.WriteLine ($"ny:{ny}, rHeight:{rHeight}");

Expand Down
13 changes: 13 additions & 0 deletions UnitTests/ToplevelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -967,5 +967,18 @@ public void Mouse_Drag_On_Top_With_Superview_Not_Null ()

Application.Run ();
}

[Fact, AutoInitShutdown]
public void EnsureVisibleBounds_With_Border_Null_Not_Throws ()
{
var top = new Toplevel ();
Application.Begin (top);

var exception = Record.Exception (() => ((FakeDriver)Application.Driver).SetBufferSize (0, 10));
Assert.Null (exception);

exception = Record.Exception (() => ((FakeDriver)Application.Driver).SetBufferSize (10, 0));
Assert.Null (exception);
}
}
}