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 = [];
promptTypes = {};
minSelectionChars = 3;
@tracked _menuState = this.CONTEXT_MENU_STATES.triggers;
@tracked _popper;
@ -107,7 +108,6 @@ export default class AiHelperContextMenu extends Component {
@bind
selectionChanged() {
if (document.activeElement !== this._dEditorInput) {
this.closeContextMenu();
return;
}
@ -129,6 +129,10 @@ export default class AiHelperContextMenu extends Component {
return;
}
if (this.selectedText?.length < this.minSelectionChars) {
return;
}
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
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
trigger_context_menu(OpenAiCompletionsInferenceStubs.translated_response)
expect(ai_helper_context_menu).to be_showing_triggers