From e598733f9b62bea4f3fb8231ba9703ec683c8374 Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Tue, 25 Jun 2024 10:15:38 -0500 Subject: [PATCH] [PM-5189] Working through further issues on positioning of inline menu --- .../background/overlay.background.spec.ts | 8 ++++--- .../autofill/background/overlay.background.ts | 21 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/browser/src/autofill/background/overlay.background.spec.ts b/apps/browser/src/autofill/background/overlay.background.spec.ts index bbbdd8a03a1..1677ebf8594 100644 --- a/apps/browser/src/autofill/background/overlay.background.spec.ts +++ b/apps/browser/src/autofill/background/overlay.background.spec.ts @@ -1296,7 +1296,7 @@ describe("OverlayBackground", () => { [focusedFieldData.frameId, null], ]); tabsSendMessageSpy.mockImplementation(); - jest.spyOn(overlayBackground as any, "repositionInlineMenu"); + jest.spyOn(overlayBackground as any, "updateInlineMenuPositionAfterRepositionEvent"); sendMockExtensionMessage( { @@ -1306,9 +1306,11 @@ describe("OverlayBackground", () => { sender, ); await flushPromises(); - jest.advanceTimersByTime(1000); + jest.advanceTimersByTime(150); - expect(overlayBackground["repositionInlineMenu"]).toHaveBeenCalled(); + expect( + overlayBackground["updateInlineMenuPositionAfterRepositionEvent"], + ).toHaveBeenCalled(); }); }); diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index f8f0c538b96..e95e5ff9d6f 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -679,7 +679,8 @@ export class OverlayBackground implements OverlayBackgroundInterface { if (subFrameOffsetsForTab) { subFrameOffsets = subFrameOffsetsForTab.get(this.focusedFieldData.frameId); if (subFrameOffsets === null) { - this.repositionInlineMenuSubject.next(sender); + this.rebuildSubFrameOffsetsSubject.next(sender); + this.startUpdateInlineMenuPositionSubject.next(sender); return; } } @@ -1196,7 +1197,7 @@ export class OverlayBackground implements OverlayBackgroundInterface { return false; } - if (this.focusedFieldData.frameId === sender.frameId) { + if (this.focusedFieldData?.frameId === sender.frameId) { return true; } @@ -1228,11 +1229,17 @@ export class OverlayBackground implements OverlayBackgroundInterface { * @param sender - The sender of the message */ private async triggerOverlayReposition(sender: chrome.runtime.MessageSender) { - if (this.checkShouldRepositionInlineMenu(sender)) { - this.cancelInlineMenuFadeInAndPositionUpdate(); - void this.toggleInlineMenuHidden({ isInlineMenuHidden: true }, sender); - this.repositionInlineMenuSubject.next(sender); + if (!this.checkShouldRepositionInlineMenu(sender)) { + return; } + + if (this.focusedFieldData.frameId > 0 && this.subFrameOffsetsForTab[sender.tab.id]) { + this.subFrameOffsetsForTab[sender.tab.id].set(this.focusedFieldData.frameId, null); + } + + this.cancelInlineMenuFadeInAndPositionUpdate(); + void this.toggleInlineMenuHidden({ isInlineMenuHidden: true }, sender); + this.repositionInlineMenuSubject.next(sender); } /** @@ -1242,8 +1249,8 @@ export class OverlayBackground implements OverlayBackgroundInterface { * @param sender - The sender of the message */ private async triggerSubFrameFocusInRebuild(sender: chrome.runtime.MessageSender) { - this.rebuildSubFrameOffsetsSubject.next(sender); this.cancelInlineMenuFadeInAndPositionUpdate(); + this.rebuildSubFrameOffsetsSubject.next(sender); this.repositionInlineMenuSubject.next(sender); }