Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit b3037b0

Browse files
committed
Make MouseEnterAndLeaveEventRouter responsible for wiring events
1 parent f711194 commit b3037b0

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/GitHub.InlineReviews/InlineCommentMarginProvider.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,13 @@ IWpfTextViewMargin CreateMargin<TGlyphTag>(IGlyphFactory<TGlyphTag> glyphFactory
6565
return margin;
6666
}
6767

68-
void TrackCommentGlyphOnDiffView(IWpfTextViewHost host, FrameworkElement marginElement)
68+
void TrackCommentGlyphOnDiffView(IWpfTextViewHost host, UIElement marginElement)
6969
{
7070
var textView = host.TextView;
7171
if (textView.Roles.Contains("DIFF"))
7272
{
73-
var hostControl = host.HostControl;
7473
var router = new MouseEnterAndLeaveEventRouter<AddInlineCommentGlyph>();
75-
hostControl.MouseMove += (t, e) => router.MouseMove(marginElement, e);
76-
hostControl.MouseLeave += (t, e) => router.MouseLeave(marginElement, e);
74+
router.Add(host.HostControl, marginElement);
7775
}
7876
}
7977

src/GitHub.InlineReviews/Tags/MouseEnterAndLeaveEventRouter.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ class MouseEnterAndLeaveEventRouter<T> where T : FrameworkElement
99
{
1010
T previousMouseOverElement;
1111

12-
public void MouseMove(object target, MouseEventArgs e)
12+
public void Add(UIElement sourceElement, UIElement targetElement)
13+
{
14+
sourceElement.MouseMove += (t, e) => MouseMove(targetElement, e);
15+
sourceElement.MouseLeave += (t, e) => MouseLeave(targetElement, e);
16+
}
17+
18+
void MouseMove(object target, MouseEventArgs e)
1319
{
1420
T mouseOverElement = null;
1521
Action<T> visitAction = element =>
@@ -27,7 +33,7 @@ public void MouseMove(object target, MouseEventArgs e)
2733
}
2834
}
2935

30-
public void MouseLeave(object target, MouseEventArgs e)
36+
void MouseLeave(object target, MouseEventArgs e)
3137
{
3238
MouseLeave(previousMouseOverElement, e);
3339
}

0 commit comments

Comments
 (0)