Skip to content

Commit 78bf9f3

Browse files
committed
Clear the queue tooltip when it is forgotten
Forget reset the row and left the caption registered. Every caller of it - the cursor leaving the canvas, and a redraw, which renumbers the rows under a cursor that has not moved - is followed by the cursor being somewhere that has no tip, which arrives as row -1. That is the row Forget just set, so Apply returned with nothing to do and the last hovered row's text stayed registered on the whole canvas: resting anywhere brought it back, over the diff panes. Which is the bug this type was written to prevent, reached from the other side. Forget clears the text as well now, and takes the control it is clearing it on.
1 parent 6727b06 commit 78bf9f3

3 files changed

Lines changed: 49 additions & 4 deletions

File tree

src/DiffEngineViewer.Windows.Tests/QueueTipsTests.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,43 @@ public async Task ForgettingLetsTheSameRowChange()
6868
using var tips = new QueueTips();
6969

7070
tips.Apply(owner, 3, "before");
71-
tips.Forget();
71+
tips.Forget(owner);
7272
tips.Apply(owner, 3, null);
7373
await Assert.That(tips.Current(owner)).IsEmpty();
7474
}
75+
76+
/// <summary>
77+
/// The reported bug reached the other way round: the cursor leaves the queue column for the
78+
/// diff panes, which is a Forget - from the mouse leaving, or from the screen being redrawn -
79+
/// followed by a row of -1.
80+
/// <para>
81+
/// Both set the row to -1, so Apply had nothing to do and returned, and the caption for the
82+
/// row last hovered stayed registered on the whole canvas. Resting anywhere brought it back,
83+
/// over the panes.
84+
/// </para>
85+
/// </summary>
86+
[Test]
87+
public async Task ForgettingBeforeLeavingTheColumnLeavesNothingRegistered()
88+
{
89+
using var owner = new Control();
90+
using var tips = new QueueTips();
91+
92+
tips.Apply(owner, 2, "SolutionA/Tests/ATests.cs:6");
93+
tips.Forget(owner);
94+
tips.Apply(owner, -1, null);
95+
96+
await Assert.That(tips.Current(owner)).IsEmpty();
97+
}
98+
99+
[Test]
100+
public async Task ForgettingClearsTheText()
101+
{
102+
using var owner = new Control();
103+
using var tips = new QueueTips();
104+
105+
tips.Apply(owner, 2, "SolutionA/Tests/ATests.cs:6");
106+
tips.Forget(owner);
107+
108+
await Assert.That(tips.Current(owner)).IsEmpty();
109+
}
75110
}

src/DiffEngineViewer.Windows/QueueTips.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,19 @@ public void Apply(Control owner, int queueRow, string? text)
5858
/// <summary>
5959
/// Forgets which row is described, so the next move re-applies. For a new screen, which
6060
/// renumbers the rows under a cursor that has not moved, and for the cursor leaving.
61+
/// <para>
62+
/// The caption goes with it. Resetting only the row left the last row's text registered on the
63+
/// whole canvas, and <see cref="Apply" />'s own early return then kept it there: a cursor on
64+
/// the canvas but not on a queue row arrives as row -1, which is the row this just set. So the
65+
/// tip popped up over the diff panes, which is the thing this type exists to prevent.
66+
/// </para>
6167
/// </summary>
62-
public void Forget() =>
68+
public void Forget(Control owner)
69+
{
6370
row = -1;
71+
tip.Hide(owner);
72+
tip.SetToolTip(owner, null);
73+
}
6474

6575
/// <summary>
6676
/// What would be shown, which is what the tests assert on: the bug this type exists to prevent

src/DiffEngineViewer.Windows/ViewerCanvas.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void Draw(Screen value)
102102
{
103103
screen = value;
104104
// A new screen renumbers the rows, so a kept index would describe a different entry.
105-
tips.Forget();
105+
tips.Forget(this);
106106
Invalidate();
107107
}
108108

@@ -498,7 +498,7 @@ protected override void OnMouseLeave(EventArgs e)
498498
Cursor = Cursors.Default;
499499
}
500500

501-
tips.Forget();
501+
tips.Forget(this);
502502
}
503503

504504
protected override void OnMouseWheel(MouseEventArgs e)

0 commit comments

Comments
 (0)