diff --git a/internal/gui/assets/settingshints.js b/internal/gui/assets/settingshints.js index 310a0abe4..9e165f7cd 100644 --- a/internal/gui/assets/settingshints.js +++ b/internal/gui/assets/settingshints.js @@ -44,9 +44,13 @@ function show(r) { card.hidden = false; // a .who the editor lays out as display: contents has no box of its own: its name's stands for it const lead = r.querySelector(":scope > .who, :scope > .txt") || r; - const who = (getComputedStyle(lead).display === "contents" ? lead.querySelector(".name") || r : lead).getBoundingClientRect(), box = r.getBoundingClientRect(); + const at = getComputedStyle(lead).display === "contents" ? lead.querySelector(".name") || r : lead; + const who = at.getBoundingClientRect(), box = r.getBoundingClientRect(); const w = card.offsetWidth, h = card.offsetHeight; - const left = Math.max(16, Math.min(who.left, innerWidth - 16 - w)); + // the card's text, not its edge, lines up with the row's name (a row with + // no name of its own has the card's edge at its own) + const pad = at === r ? 0 : parseFloat(getComputedStyle(card).paddingLeft) || 0; + const left = Math.max(16, Math.min(who.left - pad, innerWidth - 16 - w)); // under the row, or over it where the window ends first const top = box.bottom + 4 + h <= innerHeight - 8 ? box.bottom + 4 : Math.max(8, box.top - 4 - h); card.style.left = left + "px"; diff --git a/internal/gui/tests/settings-hints.test.cjs b/internal/gui/tests/settings-hints.test.cjs index 2640ed08f..31e0faad0 100644 --- a/internal/gui/tests/settings-hints.test.cjs +++ b/internal/gui/tests/settings-hints.test.cjs @@ -120,6 +120,11 @@ for (const engine of engines) { const name = await mcp.locator(":scope > .who > .name").boundingBox(), cb = await card.boundingBox(); assert.ok(cb.y >= name.y + name.height || cb.y + cb.height <= name.y, "the card covers the row's name"); assert.ok(cb.x >= 15 && cb.x + cb.width <= width - 15, `the card runs out of the window: ${JSON.stringify(cb)}`); + // its text starts where the row's name does (11-11, mmmg_btc on X: "设置里面的提示也没有对齐"), + // where the window leaves room for the card's padding to the left of it + const line = await card.locator("p").first().boundingBox(); + if (name.x >= 16 + 12) assert.ok(Math.abs(line.x - name.x) <= 1, `the card's text is at x=${line.x}, the row's name at x=${name.x}`); + else assert.ok(line.x >= name.x - 1, `the card's text is at x=${line.x}, left of the row's name at x=${name.x}`); assert.deepEqual(await page.evaluate(boxes), before, "a row moved when the card showed"); assert.equal(await card.evaluate((e) => getComputedStyle(e).pointerEvents), "none");