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 = [];
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue