fix(frontend): correct floating UI positioning under root zoom
The user font-size preference applies CSS `zoom` on `<html>` (see `composables/useFont.ts`). This breaks every popover that anchors itself with `getBoundingClientRect()` + `position: fixed/absolute`, because the rect is in visual pixels while CSS lengths are then multiplied by zoom again — shifting popovers toward the lower-right and miscomputing maxHeight / width / viewport-edge clamping. PR #1459 patched only `AgentSelector.vue` (and left its width/maxHeight unfixed). This PR introduces a shared helper `frontend/src/utils/zoom.ts` (`getRootZoom`, `rectToCssPx`, `cssViewportSize`) and applies it to every affected popover: - `AgentSelector.vue` — refactored to use the helper; also normalizes `width` and `maxHeight` (previously still in visual px). - `Input-field.vue` — model dropdown, mention popup (typed @ and button- triggered), and agent-mode dropdown. - `KnowledgeBaseSelector.vue` — primary anchor path and fallback path. - `UserMenu.vue` — tenant and IM floating submenus + viewport clamp. - `FAQTagTooltip.vue` — fixed tooltip positioning + edge clamp. - `AgentEditorModal.vue` — placeholder popups for system_prompt, context_template, and rewrite/fallback prompts. - `AgentStreamDisplay.vue` — `kb-float-popup` (absolute under body, also under the zoom containing block). Verified with `npm --prefix frontend run build`.
This commit is contained in:
@@ -410,6 +410,7 @@ import ToolResultRenderer from './ToolResultRenderer.vue';
|
||||
import ToolApprovalCard from './ToolApprovalCard.vue';
|
||||
import picturePreview from '@/components/picture-preview.vue';
|
||||
import { getChunkByIdOnly } from '@/api/knowledge-base';
|
||||
import { getRootZoom, rectToCssPx } from '@/utils/zoom';
|
||||
import { getWikiPage, type WikiPage } from '@/api/wiki';
|
||||
import { MessagePlugin } from 'tdesign-vue-next';
|
||||
import { useUIStore } from '@/stores/ui';
|
||||
@@ -737,9 +738,14 @@ const cancelFloatClose = () => {
|
||||
};
|
||||
|
||||
const openFloatForEl = (el: HTMLElement, widthAdjust = 120) => {
|
||||
const rect = el.getBoundingClientRect();
|
||||
const pageTop = window.scrollY || document.documentElement.scrollTop || 0;
|
||||
const pageLeft = window.scrollX || document.documentElement.scrollLeft || 0;
|
||||
// `.kb-float-popup` is `position: absolute` and teleported to <body>, so
|
||||
// its containing block is the initial containing block — which lives under
|
||||
// the root `zoom` in `<html>`. Convert visual-pixel measurements to CSS px
|
||||
// so the popup actually lines up with the anchor.
|
||||
const zoom = getRootZoom();
|
||||
const rect = rectToCssPx(el.getBoundingClientRect(), zoom);
|
||||
const pageTop = (window.scrollY || document.documentElement.scrollTop || 0) / zoom;
|
||||
const pageLeft = (window.scrollX || document.documentElement.scrollLeft || 0) / zoom;
|
||||
// Reduce gap to minimize mouseout triggers when moving to popup
|
||||
floatPopup.value.top = rect.bottom + pageTop + 1;
|
||||
floatPopup.value.left = rect.left + pageLeft;
|
||||
|
||||
Reference in New Issue
Block a user