DEV: Improvements to context menu (#232)

This commit is contained in:
Keegan George 2023-09-27 11:39:51 -07:00 committed by GitHub
parent 782600e64f
commit 0c50d7d553
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -42,6 +42,7 @@ export default class AiHelperContextMenu extends Component {
}; };
prompts = []; prompts = [];
promptTypes = {}; promptTypes = {};
minSelectionChars = 3;
@tracked _menuState = this.CONTEXT_MENU_STATES.triggers; @tracked _menuState = this.CONTEXT_MENU_STATES.triggers;
@tracked _popper; @tracked _popper;
@ -107,7 +108,6 @@ export default class AiHelperContextMenu extends Component {
@bind @bind
selectionChanged() { selectionChanged() {
if (document.activeElement !== this._dEditorInput) { if (document.activeElement !== this._dEditorInput) {
this.closeContextMenu();
return; return;
} }
@ -129,6 +129,10 @@ export default class AiHelperContextMenu extends Component {
return; return;
} }
if (this.selectedText?.length < this.minSelectionChars) {
return;
}
this._onSelectionChanged(); this._onSelectionChanged();
} }

View File

@ -37,6 +37,16 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
expect(ai_helper_context_menu).to have_context_menu expect(ai_helper_context_menu).to have_context_menu
end end
it "does not show the context menu when selecting insuffient text" do
visit("/latest")
page.find("#create-topic").click
composer.fill_content(OpenAiCompletionsInferenceStubs.translated_response)
page.execute_script(
"const input = document.querySelector('.d-editor-input'); input.setSelectionRange(0, 2);",
)
expect(ai_helper_context_menu).to have_no_context_menu
end
it "shows context menu in 'trigger' state when first showing" do it "shows context menu in 'trigger' state when first showing" do
trigger_context_menu(OpenAiCompletionsInferenceStubs.translated_response) trigger_context_menu(OpenAiCompletionsInferenceStubs.translated_response)
expect(ai_helper_context_menu).to be_showing_triggers expect(ai_helper_context_menu).to be_showing_triggers