From 0959d83dfd116d5356cdf6d9e08744f93ce5c218 Mon Sep 17 00:00:00 2001 From: Eran Ifrah Date: Tue, 17 Sep 2024 22:56:23 +0300 Subject: [PATCH] ChatAI: hitting ESC on either the prompt text area of the output text area, dimisses the chat AI window Signed-off-by: Eran Ifrah --- ChatAI/ChatAIWindow.cpp | 15 ++++++++++++--- ChatAI/ChatAIWindow.hpp | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ChatAI/ChatAIWindow.cpp b/ChatAI/ChatAIWindow.cpp index 9dc520dda7..7d3f08f66f 100644 --- a/ChatAI/ChatAIWindow.cpp +++ b/ChatAI/ChatAIWindow.cpp @@ -39,6 +39,7 @@ ChatAIWindow::ChatAIWindow(wxWindow* parent, ChatAIConfig& config) EventNotifier::Get()->Bind(wxEVT_LLAMACLI_STDERR, &ChatAIWindow::OnChatAIStderr, this); EventNotifier::Get()->Bind(wxEVT_LLAMACLI_TERMINATED, &ChatAIWindow::OnChatAITerminated, this); m_stcInput->Bind(wxEVT_KEY_DOWN, &ChatAIWindow::OnKeyDown, this); + m_stcOutput->Bind(wxEVT_KEY_DOWN, &ChatAIWindow::OnKeyDown, this); Bind(wxEVT_MENU, &ChatAIWindow::OnSettings, this, wxID_PREFERENCES); Bind(wxEVT_MENU, &ChatAIWindow::OnClear, this, wxID_CLEAR); m_activeModel->Bind(wxEVT_CHOICE, &ChatAIWindow::OnActiveModelChanged, this); @@ -87,6 +88,7 @@ void ChatAIWindow::UpdateTheme() void ChatAIWindow::OnKeyDown(wxKeyEvent& event) { + wxWindow* win = dynamic_cast(event.GetEventObject()); switch (event.GetKeyCode()) { case WXK_ESCAPE: { clGetManager()->ShowManagementWindow(CHAT_AI_LABEL, false); @@ -94,12 +96,12 @@ void ChatAIWindow::OnKeyDown(wxKeyEvent& event) CHECK_PTR_RET(editor); // Set the focus to the active editor - editor->GetCtrl()->CallAfter(&wxStyledTextCtrl::SetFocus); + CallAfter(&ChatAIWindow::SetFocusToActiveEditor); } break; case WXK_RETURN: case WXK_NUMPAD_ENTER: - if (event.GetModifiers() == wxMOD_SHIFT) { + if (win && win == m_stcInput && event.GetModifiers() == wxMOD_SHIFT) { // Send the command SendPromptEvent(); } else { @@ -190,4 +192,11 @@ void ChatAIWindow::OnActiveModelChanged(wxCommandEvent& event) wxString activeModel = m_activeModel->GetStringSelection(); m_config.SetSelectedModelName(activeModel); m_config.Save(); -} \ No newline at end of file +} + +void ChatAIWindow::SetFocusToActiveEditor() +{ + auto editor = clGetManager()->GetActiveEditor(); + CHECK_PTR_RET(editor); + editor->SetActive(); +} diff --git a/ChatAI/ChatAIWindow.hpp b/ChatAI/ChatAIWindow.hpp index 432eb2c189..3398c736c0 100644 --- a/ChatAI/ChatAIWindow.hpp +++ b/ChatAI/ChatAIWindow.hpp @@ -29,6 +29,7 @@ class ChatAIWindow : public AssistanceAIChatWindowBase void OnChatAITerminated(clCommandEvent& event); void PopulateModels(); void OnActiveModelChanged(wxCommandEvent& event); + void SetFocusToActiveEditor(); private: ChatAIConfig& m_config;