From 2ee8598fe2d5843e506c15895825e1d882cabf56 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Mon, 4 Mar 2024 13:11:22 -0800 Subject: [PATCH] FIX: Backspace in composer custom prompt closes menu --- .../after-d-editor/ai-helper-context-menu.js | 7 +++++-- spec/system/ai_helper/ai_composer_helper_spec.rb | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/connectors/after-d-editor/ai-helper-context-menu.js b/assets/javascripts/discourse/connectors/after-d-editor/ai-helper-context-menu.js index 193ee32d7..6bb405000 100644 --- a/assets/javascripts/discourse/connectors/after-d-editor/ai-helper-context-menu.js +++ b/assets/javascripts/discourse/connectors/after-d-editor/ai-helper-context-menu.js @@ -154,8 +154,11 @@ export default class AiHelperContextMenu extends Component { if (event.key === "Escape") { return this.closeContextMenu(); } - - if (event.key === "Backspace" && this.selectedText) { + if ( + event.key === "Backspace" && + this.selectedText && + this.menuState === this.CONTEXT_MENU_STATES.triggers + ) { return this.closeContextMenu(); } } diff --git a/spec/system/ai_helper/ai_composer_helper_spec.rb b/spec/system/ai_helper/ai_composer_helper_spec.rb index d0edaf482..4a727d000 100644 --- a/spec/system/ai_helper/ai_composer_helper_spec.rb +++ b/spec/system/ai_helper/ai_composer_helper_spec.rb @@ -65,6 +65,13 @@ def trigger_context_menu(content) expect(ai_helper_context_menu).to have_no_context_menu end + it "closes the context menu when selected text is deleted" do + trigger_context_menu(input) + expect(ai_helper_context_menu).to have_context_menu + page.send_keys(:backspace) + expect(ai_helper_context_menu).to have_no_context_menu + end + context "when using custom prompt" do let(:mode) { CompletionPrompt::CUSTOM_PROMPT } @@ -98,6 +105,15 @@ def trigger_context_menu(content) expect(composer.composer_input.value).to eq(custom_prompt_response) end end + + it "should not close the context menu if backspace is pressed" do + trigger_context_menu(input) + ai_helper_context_menu.click_ai_button + expect(ai_helper_context_menu).to have_context_menu + ai_helper_context_menu.fill_custom_prompt(custom_prompt_input) + page.find(".ai-custom-prompt__input").send_keys(:backspace) + expect(ai_helper_context_menu).to have_context_menu + end end context "when not a member of custom prompt group" do