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

Commit 7c3869f

Browse files
Bug found in #1789
- Added functionality to InlineCommentPeekViewModel to listen to the CancelEdit command of every assigned NewInlineCommentThreadViewModel - Added functionality to the InlineCommentPeekService to dismiss the session when that event is fired Co-authored-by: Steven Kirk <[email protected]>
1 parent b733591 commit 7c3869f

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/GitHub.InlineReviews/GitHub.InlineReviews.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@
191191
<Project>{9aea02db-02b5-409c-b0ca-115d05331a6b}</Project>
192192
<Name>GitHub.Exports</Name>
193193
</ProjectReference>
194+
<ProjectReference Include="..\GitHub.Extensions.Reactive\GitHub.Extensions.Reactive.csproj">
195+
<Project>{6559E128-8B40-49A5-85A8-05565ED0C7E3}</Project>
196+
<Name>GitHub.Extensions.Reactive</Name>
197+
</ProjectReference>
194198
<ProjectReference Include="..\GitHub.Extensions\GitHub.Extensions.csproj">
195199
<Project>{6AFE2E2D-6DB0-4430-A2EA-F5F5388D2F78}</Project>
196200
<Name>GitHub.Extensions</Name>

src/GitHub.InlineReviews/Services/InlineCommentPeekService.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,7 @@ public ITrackingPoint Show(ITextView textView, AddInlineCommentTag tag)
107107

108108
var session = peekBroker.TriggerPeekSession(options);
109109
var item = session.PeekableItems.OfType<InlineCommentPeekableItem>().FirstOrDefault();
110-
111-
if (item != null)
112-
{
113-
var placeholder = item.ViewModel.Thread.Comments.Last();
114-
placeholder.CancelEdit.Take(1).Subscribe(_ => session.Dismiss());
115-
}
110+
item?.ViewModel.Close.Take(1).Subscribe(_ => session.Dismiss());
116111

117112
return trackingPoint;
118113
}
@@ -134,7 +129,9 @@ public ITrackingPoint Show(ITextView textView, ShowInlineCommentTag tag)
134129

135130
ExpandCollapsedRegions(textView, line.Extent);
136131

137-
peekBroker.TriggerPeekSession(options);
132+
var session = peekBroker.TriggerPeekSession(options);
133+
var item = session.PeekableItems.OfType<InlineCommentPeekableItem>().FirstOrDefault();
134+
item?.ViewModel.Close.Take(1).Subscribe(_ => session.Dismiss());
138135

139136
return trackingPoint;
140137
}

src/GitHub.InlineReviews/ViewModels/InlineCommentPeekViewModel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using GitHub.Api;
88
using GitHub.Commands;
99
using GitHub.Extensions;
10+
using GitHub.Extensions.Reactive;
1011
using GitHub.Factories;
1112
using GitHub.InlineReviews.Commands;
1213
using GitHub.InlineReviews.Services;
@@ -63,6 +64,11 @@ public InlineCommentPeekViewModel(
6364

6465
peekSession.Dismissed += (s, e) => Dispose();
6566

67+
Close = this.WhenAnyValue(x => x.Thread)
68+
.SelectMany(x => x is NewInlineCommentThreadViewModel
69+
? x.Comments.Single().CancelEdit.SelectUnit()
70+
: Observable.Never<Unit>());
71+
6672
NextComment = ReactiveCommand.CreateAsyncTask(
6773
Observable.Return(nextCommentCommand.Enabled),
6874
_ => nextCommentCommand.Execute(new InlineCommentNavigationParams
@@ -97,6 +103,8 @@ public ICommentThreadViewModel Thread
97103
/// </summary>
98104
public ReactiveCommand<Unit> PreviousComment { get; }
99105

106+
public IObservable<Unit> Close { get; }
107+
100108
public void Dispose()
101109
{
102110
threadSubscription?.Dispose();

0 commit comments

Comments
 (0)