@@ -41,6 +41,12 @@ void UHttpGPTMessagingHandler::ProcessCompleted(const FHttpGPTResponse& Response
41
41
42
42
void UHttpGPTMessagingHandler::ProcessResponse (const FHttpGPTResponse& Response)
43
43
{
44
+ bool bScrollToEnd = false ;
45
+ if (ScrollBoxReference.IsValid ())
46
+ {
47
+ bScrollToEnd = FMath::Abs (ScrollBoxReference->GetScrollOffsetOfEnd () - ScrollBoxReference->GetScrollOffset ()) <= 8 .f ;
48
+ }
49
+
44
50
if (!Response.bSuccess )
45
51
{
46
52
const FStringFormatOrderedArguments Arguments_ErrorDetails{
@@ -63,7 +69,7 @@ void UHttpGPTMessagingHandler::ProcessResponse(const FHttpGPTResponse& Response)
63
69
return ;
64
70
}
65
71
66
- if (ScrollBoxReference.IsValid ())
72
+ if (ScrollBoxReference.IsValid () && bScrollToEnd )
67
73
{
68
74
ScrollBoxReference->ScrollToEnd ();
69
75
}
@@ -82,17 +88,32 @@ void UHttpGPTMessagingHandler::Destroy()
82
88
83
89
void SHttpGPTChatItem::Construct (const FArguments& InArgs)
84
90
{
85
- Message = FHttpGPTMessage (InArgs._MessageRole , InArgs._InputText );
86
-
87
- MessagingHandlerObject = NewObject<UHttpGPTMessagingHandler>();
88
- MessagingHandlerObject->SetFlags (RF_Standalone);
91
+ if (InArgs._MessageRole == EHttpGPTRole::Assistant)
92
+ {
93
+ MessagingHandlerObject = NewObject<UHttpGPTMessagingHandler>();
94
+ MessagingHandlerObject->SetFlags (RF_Standalone);
95
+
96
+ MessagingHandlerObject->OnMessageContentUpdated .BindLambda (
97
+ [this ](FString Content)
98
+ {
99
+ if (!Message.IsValid ())
100
+ {
101
+ return ;
102
+ }
103
+
104
+ #if ENGINE_MAJOR_VERSION > 5 || (ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1)
105
+ const FTextSelection SelectedText = Message->GetSelection ();
106
+ Message->SetText (FText::FromString (Content));
107
+ Message->SelectText (SelectedText.GetBeginning (), SelectedText.GetEnd ());
108
+ #else
109
+ Message->SetText (FText::FromString (Content));
110
+ #endif
111
+ }
112
+ );
113
+ }
89
114
90
- MessagingHandlerObject->OnMessageContentUpdated .BindLambda (
91
- [this ](FString Content)
92
- {
93
- Message.Content = Content;
94
- }
95
- );
115
+ const FText RoleText = FText::FromString (InArgs._MessageRole == EHttpGPTRole::User ? " User:" : " Assistant:" );
116
+ const FMargin SlotPadding = InArgs._MessageRole == EHttpGPTRole::User ? FMargin (Slot_Padding * 16 .f , Slot_Padding, Slot_Padding, Slot_Padding) : FMargin (Slot_Padding, Slot_Padding, Slot_Padding * 16 .f , Slot_Padding);
96
117
97
118
#if ENGINE_MAJOR_VERSION < 5
98
119
using FAppStyle = FEditorStyle;
@@ -104,7 +125,7 @@ void SHttpGPTChatItem::Construct(const FArguments& InArgs)
104
125
[
105
126
SNew (SVerticalBox)
106
127
+ SVerticalBox::Slot ()
107
- .Padding (Message. Role == EHttpGPTRole::User ? FMargin (Slot_Padding * 16 . f , Slot_Padding, Slot_Padding, Slot_Padding) : FMargin (Slot_Padding, Slot_Padding, Slot_Padding * 16 . f , Slot_Padding) )
128
+ .Padding (SlotPadding )
108
129
[
109
130
SNew (SBorder)
110
131
.BorderImage (AppStyle.GetBrush (" Menu.Background" ))
@@ -114,26 +135,34 @@ void SHttpGPTChatItem::Construct(const FArguments& InArgs)
114
135
.Padding (Slot_Padding)
115
136
.AutoHeight ()
116
137
[
117
- SNew ( STextBlock)
138
+ SAssignNew (Role, STextBlock)
118
139
.Font (FCoreStyle::GetDefaultFontStyle (" Bold" , 10 ))
119
- .Text (FText::FromString (Message. Role == EHttpGPTRole::User ? " User: " : " Assistant: " ) )
140
+ .Text (RoleText )
120
141
]
121
142
+ SVerticalBox::Slot ()
122
143
.Padding (FMargin (Slot_Padding * 4 , Slot_Padding, Slot_Padding, Slot_Padding))
123
144
.FillHeight (1 .f )
124
145
[
125
- SAssignNew (MessageBox, STextBlock)
146
+ SAssignNew (Message, SMultiLineEditableText)
147
+ .AllowMultiLine (true )
126
148
.AutoWrapText (true )
127
- .Text (this , &SHttpGPTChatItem::GetMessageText)
149
+ .IsReadOnly (true )
150
+ .AllowContextMenu (true )
151
+ .Text (FText::FromString (InArgs._InputText ))
128
152
]
129
153
]
130
154
]
131
155
];
132
156
}
133
157
134
- FText SHttpGPTChatItem::GetMessageText () const
158
+ FString SHttpGPTChatItem::GetRoleText () const
159
+ {
160
+ return Role.IsValid () ? Role->GetText ().ToString () : FString ();
161
+ }
162
+
163
+ FString SHttpGPTChatItem::GetMessageText () const
135
164
{
136
- return FText::FromString ( Message. Content );
165
+ return Message. IsValid () ? Message-> GetText (). ToString () : FString ( );
137
166
}
138
167
139
168
void SHttpGPTChatView::Construct ([[maybe_unused]] const FArguments&)
@@ -278,7 +307,7 @@ TArray<FHttpGPTMessage> SHttpGPTChatView::GetChatHistory() const
278
307
279
308
for (const auto & Item : ChatItems)
280
309
{
281
- Output.Add (Item->Message );
310
+ Output.Add (FHttpGPTMessage (* Item->GetRoleText (), Item-> GetMessageText ()) );
282
311
}
283
312
284
313
return Output;
0 commit comments