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:
@@ -1248,6 +1248,7 @@ import PromptTemplateSelector from '@/components/PromptTemplateSelector.vue';
|
||||
import ModelSelector from '@/components/ModelSelector.vue';
|
||||
import AgentShareSettings from '@/components/AgentShareSettings.vue';
|
||||
import IMChannelPanel from '@/components/IMChannelPanel.vue';
|
||||
import { getRootZoom, rectToCssPx } from '@/utils/zoom';
|
||||
import {
|
||||
evaluateToolRequirement,
|
||||
deriveKbFilterFromTools,
|
||||
@@ -2636,7 +2637,9 @@ const calculateCursorPosition = (textarea: HTMLTextAreaElement) => {
|
||||
const textBeforeCursor = formData.value.config.system_prompt.substring(0, cursorPos);
|
||||
|
||||
const style = window.getComputedStyle(textarea);
|
||||
const textareaRect = textarea.getBoundingClientRect();
|
||||
// Placeholder popup is `position: fixed` under the root zoom; normalize the
|
||||
// visual-pixel rect to CSS pixels so the popup actually lands on the caret.
|
||||
const textareaRect = rectToCssPx(textarea.getBoundingClientRect(), getRootZoom());
|
||||
|
||||
const lineHeight = parseFloat(style.lineHeight) || 20;
|
||||
const paddingTop = parseFloat(style.paddingTop) || 0;
|
||||
@@ -2791,7 +2794,8 @@ const calculateContextCursorPosition = (textarea: HTMLTextAreaElement) => {
|
||||
const textBeforeCursor = formData.value.config.context_template.substring(0, cursorPos);
|
||||
|
||||
const style = window.getComputedStyle(textarea);
|
||||
const textareaRect = textarea.getBoundingClientRect();
|
||||
// See `calculateCursorPosition` for the zoom rationale.
|
||||
const textareaRect = rectToCssPx(textarea.getBoundingClientRect(), getRootZoom());
|
||||
|
||||
const lineHeight = parseFloat(style.lineHeight) || 20;
|
||||
const paddingTop = parseFloat(style.paddingTop) || 0;
|
||||
@@ -2951,7 +2955,8 @@ const calculateGenericCursorPosition = (textarea: HTMLTextAreaElement, fieldValu
|
||||
const currentLine = lines.length - 1;
|
||||
const currentLineText = lines[currentLine];
|
||||
|
||||
const textareaRect = textarea.getBoundingClientRect();
|
||||
// See `calculateCursorPosition` for the zoom rationale.
|
||||
const textareaRect = rectToCssPx(textarea.getBoundingClientRect(), getRootZoom());
|
||||
const style = window.getComputedStyle(textarea);
|
||||
const lineHeight = parseFloat(style.lineHeight) || 20;
|
||||
const paddingTop = parseFloat(style.paddingTop) || 0;
|
||||
|
||||
@@ -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