DEV: Improvements to context menu (#232)
This commit is contained in:
parent
782600e64f
commit
0c50d7d553
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue