diff --git a/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs b/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs index 990e7bf..067b36a 100644 --- a/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs @@ -46,6 +46,19 @@ public string GetUnescapedIssueQuery() return Uri.UnescapeDataString(GetIssueQuery()).Replace('+', ' '); } + // If the user changed the URL after clicking submit and clicked + // saved just after, we change it back to what was before to not corrupt our saved data. + private void CorrectUrl() + { + var configurationData = JsonNode.Parse(ConfigurationData); + if (configurationData != null) + { + configurationData["url"] = RepositoryUrl; + ConfigurationData = configurationData.ToJsonString(); + UpdateWidget(); + } + } + public override void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs) { var verb = GetWidgetActionForVerb(actionInvokedArgs.Verb); @@ -60,6 +73,7 @@ public override void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs) case WidgetAction.Save: UpdateTitle(JsonNode.Parse(actionInvokedArgs.Data)); base.OnActionInvoked(actionInvokedArgs); + CorrectUrl(); break; default: @@ -256,7 +270,7 @@ public string GetConfiguration(string dataUrl) { "owner", repository.Owner.Login }, { "milestone", string.Empty }, { "project", repository.Description }, - { "url", repository.HtmlUrl }, + { "url", RepositoryUrl }, { "query", GetUnescapedIssueQuery() }, };