From 896d19551af906a7af367cd772fcd7c639939292 Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Tue, 29 Oct 2024 16:55:40 -0500 Subject: [PATCH] [PM-14054] Fixing scroll-based repositioning of inline menu when inline menu is focused (#11770) --- .../src/autofill/content/bootstrap-autofill-overlay-menu.ts | 1 + .../src/autofill/content/bootstrap-autofill-overlay.ts | 1 + .../services/autofill-overlay-content.service.spec.ts | 6 +++++- .../autofill/services/autofill-overlay-content.service.ts | 5 ++++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/browser/src/autofill/content/bootstrap-autofill-overlay-menu.ts b/apps/browser/src/autofill/content/bootstrap-autofill-overlay-menu.ts index 3593064792..cd22e1e535 100644 --- a/apps/browser/src/autofill/content/bootstrap-autofill-overlay-menu.ts +++ b/apps/browser/src/autofill/content/bootstrap-autofill-overlay-menu.ts @@ -21,6 +21,7 @@ import AutofillInit from "./autofill-init"; domQueryService, domElementVisibilityService, inlineMenuFieldQualificationService, + inlineMenuContentService, ); windowContext.bitwardenAutofillInit = new AutofillInit( diff --git a/apps/browser/src/autofill/content/bootstrap-autofill-overlay.ts b/apps/browser/src/autofill/content/bootstrap-autofill-overlay.ts index 174a695b76..11c8e4afd6 100644 --- a/apps/browser/src/autofill/content/bootstrap-autofill-overlay.ts +++ b/apps/browser/src/autofill/content/bootstrap-autofill-overlay.ts @@ -24,6 +24,7 @@ import AutofillInit from "./autofill-init"; domQueryService, domElementVisibilityService, inlineMenuFieldQualificationService, + inlineMenuContentService, ); windowContext.bitwardenAutofillInit = new AutofillInit( diff --git a/apps/browser/src/autofill/services/autofill-overlay-content.service.spec.ts b/apps/browser/src/autofill/services/autofill-overlay-content.service.spec.ts index 91ad63955c..49a0b3ca84 100644 --- a/apps/browser/src/autofill/services/autofill-overlay-content.service.spec.ts +++ b/apps/browser/src/autofill/services/autofill-overlay-content.service.spec.ts @@ -1,4 +1,4 @@ -import { mock } from "jest-mock-extended"; +import { mock, MockProxy } from "jest-mock-extended"; import { EVENTS } from "@bitwarden/common/autofill/constants"; import { CipherType } from "@bitwarden/common/vault/enums"; @@ -13,6 +13,7 @@ import { import AutofillField from "../models/autofill-field"; import AutofillForm from "../models/autofill-form"; import AutofillPageDetails from "../models/autofill-page-details"; +import { AutofillInlineMenuContentService } from "../overlay/inline-menu/abstractions/autofill-inline-menu-content.service"; import { createAutofillFieldMock } from "../spec/autofill-mocks"; import { flushPromises, @@ -35,6 +36,7 @@ describe("AutofillOverlayContentService", () => { let domElementVisibilityService: DomElementVisibilityService; let autofillInit: AutofillInit; let inlineMenuFieldQualificationService: InlineMenuFieldQualificationService; + let inlineMenuContentService: MockProxy; let autofillOverlayContentService: AutofillOverlayContentService; let sendExtensionMessageSpy: jest.SpyInstance; const sendResponseSpy = jest.fn(); @@ -44,10 +46,12 @@ describe("AutofillOverlayContentService", () => { inlineMenuFieldQualificationService = new InlineMenuFieldQualificationService(); domQueryService = new DomQueryService(); domElementVisibilityService = new DomElementVisibilityService(); + inlineMenuContentService = mock(); autofillOverlayContentService = new AutofillOverlayContentService( domQueryService, domElementVisibilityService, inlineMenuFieldQualificationService, + inlineMenuContentService, ); autofillInit = new AutofillInit( domQueryService, diff --git a/apps/browser/src/autofill/services/autofill-overlay-content.service.ts b/apps/browser/src/autofill/services/autofill-overlay-content.service.ts index 645795d9f2..ea3c578494 100644 --- a/apps/browser/src/autofill/services/autofill-overlay-content.service.ts +++ b/apps/browser/src/autofill/services/autofill-overlay-content.service.ts @@ -28,6 +28,7 @@ import { } from "../enums/autofill-overlay.enum"; import AutofillField from "../models/autofill-field"; import AutofillPageDetails from "../models/autofill-page-details"; +import { AutofillInlineMenuContentService } from "../overlay/inline-menu/abstractions/autofill-inline-menu-content.service"; import { ElementWithOpId, FillableFormFieldElement, FormFieldElement } from "../types"; import { currentlyInSandboxedIframe, @@ -155,6 +156,7 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ private domQueryService: DomQueryService, private domElementVisibilityService: DomElementVisibilityService, private inlineMenuFieldQualificationService: InlineMenuFieldQualificationService, + private inlineMenuContentService?: AutofillInlineMenuContentService, ) {} /** @@ -1580,7 +1582,8 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ if (activeElement) { return ( activeElement === this.mostRecentlyFocusedField || - activeElement.contains(this.mostRecentlyFocusedField) + activeElement.contains(this.mostRecentlyFocusedField) || + this.inlineMenuContentService?.isElementInlineMenu(activeElement as HTMLElement) ); }