Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: selectable chat history
  • Loading branch information
ryo0ka committed Sep 14, 2025
commit e9a3a4721cb42b060161231b43955c984283c8a5
2 changes: 1 addition & 1 deletion Torch.Server/Views/ChatControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ScrollViewer x:Name="ChatScroller" Grid.Row="0" Margin="5,5,5,5" HorizontalScrollBarVisibility="Disabled">
<TextBlock x:Name="ChatItems" TextWrapping="Wrap" />
<RichTextBox x:Name="ChatItems" IsReadOnly="True" BorderThickness="0" Background="Transparent" VerticalScrollBarVisibility="Hidden" />
</ScrollViewer>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
Expand Down
15 changes: 12 additions & 3 deletions Torch.Server/Views/ChatControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void Server_Initialized(ITorchServer obj)
{
Dispatcher.InvokeAsync(() =>
{
ChatItems.Inlines.Clear();
ChatItems.Document.Blocks.Clear();
});

var sessionManager = _server.Managers.GetManager<ITorchSessionManager>();
Expand All @@ -88,7 +88,7 @@ private void SessionStateChanged(ITorchSession session, TorchSessionState state)
switch (state)
{
case TorchSessionState.Loading:
Dispatcher.InvokeAsync(() => ChatItems.Inlines.Clear());
Dispatcher.InvokeAsync(() => ChatItems.Document.Blocks.Clear());
break;
case TorchSessionState.Loaded:
{
Expand Down Expand Up @@ -131,6 +131,14 @@ private void InsertMessage(TorchChatMessage msg)
if (Dispatcher.CheckAccess())
{
bool atBottom = ChatScroller.VerticalOffset + 8 > ChatScroller.ScrollableHeight;

// We'll maintain a single paragraph for all messages:
if (!(ChatItems.Document.Blocks.FirstBlock is Paragraph firstBlock))
{
firstBlock = new Paragraph();
ChatItems.Document.Blocks.Add(firstBlock);
}

var span = new Span();
span.Inlines.Add($"{msg.Timestamp} ");
switch (msg.Channel)
Expand All @@ -145,7 +153,8 @@ private void InsertMessage(TorchChatMessage msg)
span.Inlines.Add(new Run(msg.Author) { Foreground = LookupBrush(msg.Font) });
span.Inlines.Add($": {msg.Message}");
span.Inlines.Add(new LineBreak());
ChatItems.Inlines.Add(span);
firstBlock.Inlines.Add(span);

if (atBottom)
ChatScroller.ScrollToBottom();
}
Expand Down