FIX: Backspace in composer custom prompt closes menu (#505)

This commit is contained in:
Keegan George 2024-03-04 13:33:31 -08:00 committed by GitHub
parent 77cf9e2cff
commit cee1b3d275
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 2 deletions

View File

@ -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();
}
}

View File

@ -65,6 +65,13 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
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 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
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