Skip to content

Commit 202cc45

Browse files
committed
Handling arrow up/down in AI Chat to scroll through earlier questions
1 parent 34e0f78 commit 202cc45

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

FetchXmlBuilder/DockControls/AiChatControl.cs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public partial class AiChatControl : WeifenLuo.WinFormsUI.Docking.DockContent
3939
private int manualcalls = 0; // Counts the number of calls made by the user in this session
4040
private static List<AiUser> freeusers;
4141
private bool metadataavailable;
42+
private List<string> askhistory = new List<string>();
43+
private int currentaskhistory = -1;
4244

4345
#region Public Constructor
4446

@@ -265,6 +267,7 @@ private void SendChatToAI(object sender, EventArgs e = null)
265267
{
266268
case Button btn when btn == btnAiChatAsk:
267269
text = txtAiChat.Text;
270+
AddHistoryIfNeeded(text);
268271
break;
269272

270273
case Button btn when btn == btnYes:
@@ -284,6 +287,7 @@ private void SendChatToAI(object sender, EventArgs e = null)
284287

285288
case string manual:
286289
text = manual;
290+
AddHistoryIfNeeded(text);
287291
break;
288292
}
289293
if (string.IsNullOrWhiteSpace(text))
@@ -611,6 +615,35 @@ private void Log(string action, double? count = null, double? duration = null, l
611615
ai.WriteEvent($"{action}", count ?? msg?.Length, duration, tokensout, tokensin, logconversation ? msg : null);
612616
}
613617

618+
private void AddHistoryIfNeeded(string text)
619+
{
620+
if (currentaskhistory < 0 || currentaskhistory >= askhistory.Count || askhistory[currentaskhistory] != text)
621+
{
622+
askhistory.Add(text);
623+
currentaskhistory = askhistory.Count;
624+
}
625+
}
626+
627+
private void CopyFromHistory(int direction)
628+
{
629+
currentaskhistory += direction;
630+
if (currentaskhistory < 0)
631+
{
632+
currentaskhistory = 0;
633+
}
634+
else if (currentaskhistory >= askhistory.Count)
635+
{
636+
currentaskhistory = askhistory.Count;
637+
txtAiChat.Text = string.Empty;
638+
return;
639+
}
640+
if (currentaskhistory >= 0 && currentaskhistory < askhistory.Count)
641+
{
642+
txtAiChat.Text = askhistory[currentaskhistory];
643+
txtAiChat.SelectionStart = txtAiChat.Text.Length;
644+
}
645+
}
646+
614647
#endregion Private Methods
615648

616649
#region Private Event Handlers
@@ -648,6 +681,14 @@ private void txtAiChatAsk_KeyDown(object sender, KeyEventArgs e)
648681
SendChatToAI(txtAiChat.Text);
649682
break;
650683

684+
case Keys.Up:
685+
CopyFromHistory(-1);
686+
break;
687+
688+
case Keys.Down:
689+
CopyFromHistory(1);
690+
break;
691+
651692
default:
652693
return;
653694
}
@@ -752,13 +793,13 @@ private void mnuFree_Click(object sender, EventArgs e)
752793
}
753794
}
754795

755-
#endregion Private Event Handlers
756-
757796
private void mnuSendWithEnter_Click(object sender, EventArgs e)
758797
{
759798
fxb.settings.AiSettings.SendWithEnter = mnuSendWithEnter.Checked;
760799
fxb.settings.Save();
761800
}
801+
802+
#endregion Private Event Handlers
762803
}
763804

764805
public class AiUser

0 commit comments

Comments
 (0)