Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ describe("BreakpointConditionInputComponent", () => {
}) as HTMLDivElement,
getBottomForLineNumber: () => 40,
getScrollTop: () => 5,
getScrollLeft: () => 0,
dispose: vi.fn(),
} as unknown as editor.IStandaloneCodeEditor;

Expand All @@ -78,46 +77,6 @@ describe("BreakpointConditionInputComponent", () => {
* expectation below is a specific number rather than a zero that jsdom would produce anyway.
*/
describe("popup placement", () => {
it("offsets left by the glyph margin and the fixed popup width", () => {
// 30 (rect.left) + 10 (glyphMarginLeft) - 0 (scrollLeft) - 160 (popup width)
expect(component.left()).toBe(-120);
});

it("places the top at the bottom of the target line, less the scroll offset", () => {
// 20 (rect.top) + 40 (line bottom) - 5 (scrollTop)
expect(component.top()).toBe(55);
});

it("subtracts the horizontal scroll offset", () => {
// Only left() reads scrollLeft; a copy-paste of top()'s body would miss this.
component.monacoEditor = {
...component.monacoEditor,
getScrollLeft: () => 25,
} as unknown as editor.IStandaloneCodeEditor;

expect(component.left()).toBe(-145);
});

it("falls back to 0 rather than throwing when there is no editor yet", () => {
const stub = component.monacoEditor;
component.monacoEditor = undefined as unknown as editor.IStandaloneCodeEditor;
try {
// The guards exist because the popup can be rendered a tick before the editor is attached.
expect(component.left()).toBe(0);
expect(component.top()).toBe(0);
} finally {
// afterEach disposes the editor, so put the stub back.
component.monacoEditor = stub;
}
});

it("falls back to 0 for top() when no line is targeted", () => {
component.lineNum = undefined;
expect(component.top()).toBe(0);
// left() does not depend on the line, so it still resolves.
expect(component.left()).toBe(-120);
});

it("writes both css offsets when the target line changes", () => {
mockUdfDebugService.getCondition.mockReturnValue("x > 1");
component.lineNum = 3;
Expand All @@ -142,7 +101,6 @@ describe("BreakpointConditionInputComponent", () => {
getDomNode: () => undefined,
getBottomForLineNumber: () => 40,
getScrollTop: () => 5,
getScrollLeft: () => 0,
dispose: vi.fn(),
} as unknown as editor.IStandaloneCodeEditor;
component.lineNum = 3;
Expand All @@ -156,8 +114,6 @@ describe("BreakpointConditionInputComponent", () => {
expect(component.topPosition).toBe("35px");
// left: 0 (no rect) + 0 (glyph margin) - 160 (popup width)
expect(component.leftPosition).toBe("-160px");
// top() reaches the same missing rect through its own fallback.
expect(component.top()).toBe(35);
});

it("defaults the condition to empty when the debugger holds none for that line", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,6 @@ export class BreakpointConditionInputComponent implements OnChanges {
this.leftPosition = `${leftValue}px`;
}

public left(): number {
if (!isDefined(this.monacoEditor)) {
return 0;
}

// Calculate the left position of the input popup based on the editor layout
const { glyphMarginLeft } = this.monacoEditor.getLayoutInfo()!;
const { left } = this.monacoEditor.getDomNode()!.getBoundingClientRect();
return left + glyphMarginLeft - this.monacoEditor.getScrollLeft() - 160;
}

public top(): number {
if (!(isDefined(this.monacoEditor) && isDefined(this.lineNum))) {
return 0;
}

// Calculate the top position of the input popup based on the editor layout
const topPixel = this.monacoEditor.getBottomForLineNumber(this.lineNum);
const editorRect = this.monacoEditor.getDomNode()?.getBoundingClientRect();
return (editorRect?.top || 0) + topPixel - this.monacoEditor.getScrollTop();
}

get isVisible(): boolean {
return isDefined(this.lineNum);
}
Expand Down
Loading