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

Commit 9e4d7f9

Browse files
Starting to implement autocomplete functionality
1 parent c3fa22d commit 9e4d7f9

File tree

2 files changed

+41
-21
lines changed

2 files changed

+41
-21
lines changed

src/GitHub.VisualStudio.UI/Views/GitHubPane/PullRequestCreationView.xaml

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,35 @@
149149
SpellCheck.IsEnabled="True"
150150
AutomationProperties.AutomationId="{x:Static ghfvs:AutomationIDs.PullRequestCreationTitleTextBox}"/>
151151

152-
<ghfvs:PromptTextBox Grid.Row="2"
153-
MinHeight="100"
154-
Margin="10,5"
155-
AcceptsReturn="True"
156-
PromptText="{x:Static ghfvs:Resources.Description}"
157-
Text="{Binding Description, UpdateSourceTrigger=PropertyChanged}"
158-
Style="{DynamicResource GitHubVsPromptTextBox}"
159-
VerticalScrollBarVisibility="Auto"
160-
TextWrapping="Wrap"
161-
SpellCheck.IsEnabled="True"
162-
AutomationProperties.AutomationId="{x:Static ghfvs:AutomationIDs.PullRequestCreationDescriptionTextBox}"/>
163-
152+
<ghfvs:AutoCompleteBox
153+
x:Name="commitMessageTextBox"
154+
ScrollViewer.CanContentScroll="False"
155+
Margin="0"
156+
HorizontalAlignment="Stretch"
157+
TabIndex="0"
158+
TextBoxStyle="{StaticResource GitHubPromptRichText}">
159+
<ghfvs:AutoCompleteBox.ItemTemplate>
160+
<DataTemplate>
161+
<ghfvs:AutoCompleteSuggestionView ViewModel="{Binding}" />
162+
</DataTemplate>
163+
</ghfvs:AutoCompleteBox.ItemTemplate>
164+
<ghfvs:AutoCompleteBox.InputElement>
165+
<ghfvs:TextBoxAutoCompleteTextInput>
166+
<ghfvs:PromptTextBox Grid.Row="2"
167+
MinHeight="100"
168+
Margin="10,5"
169+
AcceptsReturn="True"
170+
PromptText="{x:Static ghfvs:Resources.Description}"
171+
Text="{Binding Description, UpdateSourceTrigger=PropertyChanged}"
172+
Style="{DynamicResource GitHubVsPromptTextBox}"
173+
VerticalScrollBarVisibility="Auto"
174+
TextWrapping="Wrap"
175+
SpellCheck.IsEnabled="True"
176+
AutomationProperties.AutomationId="{x:Static ghfvs:AutomationIDs.PullRequestCreationDescriptionTextBox}"/>
177+
</ghfvs:TextBoxAutoCompleteTextInput>
178+
</ghfvs:AutoCompleteBox.InputElement>
179+
</ghfvs:AutoCompleteBox>
180+
164181
<ghfvs:ValidationMessage x:Name="titleValidationMessage"
165182
Grid.Row="3"
166183
Fill="{StaticResource GitHubWarningBrush}"

test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestCreationViewModelTests.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct TestData
5555
public IConnection Connection;
5656
public IApiClient ApiClient;
5757
public IModelService ModelService;
58+
public IAutoCompleteAdvisor AutoCompleteAdvisor { get; set; }
5859

5960
public IModelServiceFactory GetModelServiceFactory()
6061
{
@@ -78,6 +79,7 @@ static TestData PrepareTestData(
7879
var connection = Substitute.For<IConnection>();
7980
var api = Substitute.For<IApiClient>();
8081
var ms = Substitute.For<IModelService>();
82+
var autoCompleteAdvisor = Substitute.For<IAutoCompleteAdvisor>();
8183

8284
connection.HostAddress.Returns(HostAddress.Create("https://github.com"));
8385

@@ -121,7 +123,8 @@ static TestData PrepareTestData(
121123
NotificationService = notifications,
122124
Connection = connection,
123125
ApiClient = api,
124-
ModelService = ms
126+
ModelService = ms,
127+
AutoCompleteAdvisor = autoCompleteAdvisor
125128
};
126129
}
127130

@@ -147,7 +150,7 @@ public async Task TargetBranchDisplayNameIncludesRepoOwnerWhenForkAsync()
147150
var prservice = new PullRequestService(data.GitClient, data.GitService, Substitute.For<IVSGitExt>(), Substitute.For<IGraphQLClientFactory>(), data.ServiceProvider.GetOperatingSystem(), Substitute.For<IUsageTracker>());
148151
prservice.GetPullRequestTemplate(data.ActiveRepo).Returns(Observable.Empty<string>());
149152
var vm = new PullRequestCreationViewModel(data.GetModelServiceFactory(), prservice, data.NotificationService,
150-
Substitute.For<IMessageDraftStore>(), data.GitService);
153+
Substitute.For<IMessageDraftStore>(), data.GitService, data.AutoCompleteAdvisor);
151154
await vm.InitializeAsync(data.ActiveRepo, data.Connection);
152155
Assert.That("octokit/master", Is.EqualTo(vm.TargetBranch.DisplayName));
153156
}
@@ -183,7 +186,7 @@ public async Task CreatingPRsAsync(
183186

184187
var prservice = new PullRequestService(data.GitClient, data.GitService, Substitute.For<IVSGitExt>(), Substitute.For<IGraphQLClientFactory>(), data.ServiceProvider.GetOperatingSystem(), Substitute.For<IUsageTracker>());
185188
var vm = new PullRequestCreationViewModel(data.GetModelServiceFactory(), prservice, data.NotificationService,
186-
Substitute.For<IMessageDraftStore>(), data.GitService);
189+
Substitute.For<IMessageDraftStore>(), data.GitService, data.AutoCompleteAdvisor);
187190
await vm.InitializeAsync(data.ActiveRepo, data.Connection);
188191

189192
// the TargetBranch property gets set to whatever the repo default is (we assume master here),
@@ -226,7 +229,7 @@ public async Task TemplateIsUsedIfPresentAsync()
226229
prservice.GetPullRequestTemplate(data.ActiveRepo).Returns(Observable.Return("Test PR template"));
227230

228231
var vm = new PullRequestCreationViewModel(data.GetModelServiceFactory(), prservice, data.NotificationService,
229-
Substitute.For<IMessageDraftStore>(), data.GitService);
232+
Substitute.For<IMessageDraftStore>(), data.GitService, data.AutoCompleteAdvisor);
230233
await vm.InitializeAsync(data.ActiveRepo, data.Connection);
231234

232235
Assert.That("Test PR template", Is.EqualTo(vm.Description));
@@ -246,7 +249,7 @@ public async Task LoadsDraft()
246249

247250
var prservice = Substitute.For<IPullRequestService>();
248251
var vm = new PullRequestCreationViewModel(data.GetModelServiceFactory(), prservice, data.NotificationService,
249-
draftStore, data.GitService);
252+
draftStore, data.GitService, data.AutoCompleteAdvisor);
250253
await vm.InitializeAsync(data.ActiveRepo, data.Connection);
251254

252255
Assert.That(vm.PRTitle, Is.EqualTo("This is a Title."));
@@ -261,7 +264,7 @@ public async Task UpdatesDraftWhenDescriptionChanges()
261264
var draftStore = Substitute.For<IMessageDraftStore>();
262265
var prservice = Substitute.For<IPullRequestService>();
263266
var vm = new PullRequestCreationViewModel(data.GetModelServiceFactory(), prservice, data.NotificationService,
264-
draftStore, data.GitService, scheduler);
267+
draftStore, data.GitService, data.AutoCompleteAdvisor, scheduler);
265268
await vm.InitializeAsync(data.ActiveRepo, data.Connection);
266269

267270
vm.Description = "Body changed.";
@@ -284,7 +287,7 @@ public async Task UpdatesDraftWhenTitleChanges()
284287
var draftStore = Substitute.For<IMessageDraftStore>();
285288
var prservice = Substitute.For<IPullRequestService>();
286289
var vm = new PullRequestCreationViewModel(data.GetModelServiceFactory(), prservice, data.NotificationService,
287-
draftStore, data.GitService, scheduler);
290+
draftStore, data.GitService, data.AutoCompleteAdvisor, scheduler);
288291
await vm.InitializeAsync(data.ActiveRepo, data.Connection);
289292

290293
vm.PRTitle = "Title changed.";
@@ -307,7 +310,7 @@ public async Task DeletesDraftWhenPullRequestSubmitted()
307310
var draftStore = Substitute.For<IMessageDraftStore>();
308311
var prservice = Substitute.For<IPullRequestService>();
309312
var vm = new PullRequestCreationViewModel(data.GetModelServiceFactory(), prservice, data.NotificationService, draftStore,
310-
data.GitService, scheduler);
313+
data.GitService, data.AutoCompleteAdvisor, scheduler);
311314
await vm.InitializeAsync(data.ActiveRepo, data.Connection);
312315

313316
await vm.CreatePullRequest.Execute();
@@ -323,7 +326,7 @@ public async Task DeletesDraftWhenCanceled()
323326
var draftStore = Substitute.For<IMessageDraftStore>();
324327
var prservice = Substitute.For<IPullRequestService>();
325328
var vm = new PullRequestCreationViewModel(data.GetModelServiceFactory(), prservice, data.NotificationService, draftStore,
326-
data.GitService, scheduler);
329+
data.GitService, data.AutoCompleteAdvisor, scheduler);
327330
await vm.InitializeAsync(data.ActiveRepo, data.Connection);
328331

329332
await vm.Cancel.Execute();

0 commit comments

Comments
 (0)