Skip to content

Commit

Permalink
ChatAI: hitting ESC on either the prompt text area of the output text…
Browse files Browse the repository at this point in the history
… area, dimisses the chat AI window

Signed-off-by: Eran Ifrah <eran@codelite.org>
  • Loading branch information
eranif committed Sep 17, 2024
1 parent 6ad0b45 commit 0959d83
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions ChatAI/ChatAIWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -87,19 +88,20 @@ void ChatAIWindow::UpdateTheme()

void ChatAIWindow::OnKeyDown(wxKeyEvent& event)
{
wxWindow* win = dynamic_cast<wxWindow*>(event.GetEventObject());
switch (event.GetKeyCode()) {
case WXK_ESCAPE: {
clGetManager()->ShowManagementWindow(CHAT_AI_LABEL, false);
auto editor = clGetManager()->GetActiveEditor();
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 {
Expand Down Expand Up @@ -190,4 +192,11 @@ void ChatAIWindow::OnActiveModelChanged(wxCommandEvent& event)
wxString activeModel = m_activeModel->GetStringSelection();
m_config.SetSelectedModelName(activeModel);
m_config.Save();
}
}

void ChatAIWindow::SetFocusToActiveEditor()
{
auto editor = clGetManager()->GetActiveEditor();
CHECK_PTR_RET(editor);
editor->SetActive();
}
1 change: 1 addition & 0 deletions ChatAI/ChatAIWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ChatAIWindow : public AssistanceAIChatWindowBase
void OnChatAITerminated(clCommandEvent& event);
void PopulateModels();
void OnActiveModelChanged(wxCommandEvent& event);
void SetFocusToActiveEditor();

private:
ChatAIConfig& m_config;
Expand Down

0 comments on commit 0959d83

Please sign in to comment.