typeahead: Ignore mouse position for selection until it's moved.

Added a property `mouse_moved_since_typeahead` to the typeahead class
which tracks whether the mouse has been moved since the typeahead
menu appeared.

The hovered over menu item is highlighted on `mouseenter` only if
`mouseMoved` is true. Otherwise, the cursor is hidden temporarily.

Code substantially reorganized by tabbott.

Fixes: #21018.
This commit is contained in:
N-Shar-ma
2022-02-06 23:51:17 +05:30
committed by Tim Abbott
parent 653af70d5a
commit 728fee31b2
3 changed files with 33 additions and 1 deletions

View File

@@ -491,6 +491,11 @@ class CommonUtils {
`//*[@class="typeahead dropdown-menu" and contains(@style, "display: block")]//li[contains(normalize-space(), "${item}")]//a`,
{visible: true},
);
const entry_x = (await entry?.boundingBox())?.x;
const entry_y = (await entry?.boundingBox())?.y;
if (entry_x && entry_y) {
await page.mouse.move(entry_x, entry_y);
}
await page.evaluate((entry) => {
entry.click();
}, entry);

View File

@@ -229,6 +229,9 @@ async function get_suggestions(page: Page, str: string): Promise<void> {
async function select_from_suggestions(page: Page, item: string): Promise<void> {
await page.evaluate((item: string) => {
const tah = $(".create_default_stream").data().typeahead;
tah.mousemove({
currentTarget: $(`.typeahead:visible li:contains("${CSS.escape(item)}")`)[0],
});
tah.mouseenter({
currentTarget: $(`.typeahead:visible li:contains("${CSS.escape(item)}")`)[0],
});