From dfc69e28db805a43817ef9ca6a9b297b74323d3d Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Thu, 5 Sep 2024 20:06:58 +0200 Subject: [PATCH] Fixed scrolling issue after send to chat call --- app/MindWork AI Studio/Pages/Chat.razor.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/MindWork AI Studio/Pages/Chat.razor.cs b/app/MindWork AI Studio/Pages/Chat.razor.cs index de06016c..e3ff30e6 100644 --- a/app/MindWork AI Studio/Pages/Chat.razor.cs +++ b/app/MindWork AI Studio/Pages/Chat.razor.cs @@ -44,6 +44,7 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable private bool workspacesVisible; private Workspaces? workspaces; private bool mustScrollToBottomAfterRender; + private byte scrollRenderCountdown; // Unfortunately, we need the input field reference to clear it after sending a message. // This is necessary because we have to handle the key events ourselves. Otherwise, @@ -76,6 +77,13 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable }; } } + + if (this.SettingsManager.ConfigurationData.Chat.ShowLatestMessageAfterLoading) + { + this.mustScrollToBottomAfterRender = true; + this.scrollRenderCountdown = 2; + this.StateHasChanged(); + } } await base.OnInitializedAsync(); @@ -85,8 +93,15 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable { if(this.mustScrollToBottomAfterRender) { - await this.scrollingArea.ScrollToBottom(); - this.mustScrollToBottomAfterRender = false; + if (--this.scrollRenderCountdown == 0) + { + await this.scrollingArea.ScrollToBottom(); + this.mustScrollToBottomAfterRender = false; + } + else + { + this.StateHasChanged(); + } } await base.OnAfterRenderAsync(firstRender); @@ -384,6 +399,7 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable if (this.SettingsManager.ConfigurationData.Chat.ShowLatestMessageAfterLoading) { this.mustScrollToBottomAfterRender = true; + this.scrollRenderCountdown = 2; this.StateHasChanged(); } }