From 5681bf489df00214a10bf48e39f5fbef14502bf9 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 29 Apr 2025 09:14:24 +0800 Subject: [PATCH] fix: empty dialog when generating commit message with AI (#1257) Signed-off-by: leo --- src/Views/AIAssistant.axaml | 4 ++-- src/Views/AIAssistant.axaml.cs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Views/AIAssistant.axaml b/src/Views/AIAssistant.axaml index c9a37f3b..96ce56ec 100644 --- a/src/Views/AIAssistant.axaml +++ b/src/Views/AIAssistant.axaml @@ -39,12 +39,12 @@ + Background="{DynamicResource Brush.Contents}" + Content="{Binding Text}"/> diff --git a/src/Views/AIAssistant.axaml.cs b/src/Views/AIAssistant.axaml.cs index f8519b7c..f865cabe 100644 --- a/src/Views/AIAssistant.axaml.cs +++ b/src/Views/AIAssistant.axaml.cs @@ -15,6 +15,15 @@ namespace SourceGit.Views { public class AIResponseView : TextEditor { + public static readonly StyledProperty ContentProperty = + AvaloniaProperty.Register(nameof(Content), string.Empty); + + public string Content + { + get => GetValue(ContentProperty); + set => SetValue(ContentProperty, value); + } + protected override Type StyleKeyOverride => typeof(TextEditor); public AIResponseView() : base(new TextArea(), new TextDocument()) @@ -58,6 +67,16 @@ namespace SourceGit.Views GC.Collect(); } + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + + if (change.Property == ContentProperty) + { + Text = Content; + } + } + private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e) { var selected = SelectedText;