fix: 优化浮动菜单位置计算与 token 处理

This commit is contained in:
JOJO 2026-07-15 04:37:26 +08:00
parent 089291f77e
commit 11ffdc2bb5
2 changed files with 51 additions and 24 deletions

View File

@ -2301,32 +2301,52 @@ const updateFloatingMenuPosition = async () => {
const padding = 16;
const gap = 10;
const menuHeight = menu?.getBoundingClientRect().height || 0;
let top: number;
if (menuHeight > 0) {
const spaceBelow = window.innerHeight - rect.bottom - padding;
const spaceAbove = rect.top - padding;
if (spaceBelow >= menuHeight) {
top = rect.bottom + gap;
} else if (spaceAbove >= menuHeight) {
top = rect.top - menuHeight - gap;
} else if (spaceBelow >= spaceAbove) {
// max-height
top = Math.max(rect.bottom + gap, window.innerHeight - menuHeight - padding);
} else {
//
top = padding;
}
} else {
top = Math.max(padding, Math.min(rect.bottom + gap, window.innerHeight - 80));
// 4 max-height
const optionEl = menu?.querySelector<HTMLElement>('.settings-menu-option');
const optionHeight = optionEl ? optionEl.getBoundingClientRect().height : 44;
const menuPadding = 12; // menu padding 6px top + 6px bottom
const fixedMaxHeight = Math.round(optionHeight * 4) + menuPadding;
//
if (menu) {
menu.style.maxHeight = `${fixedMaxHeight}px`;
}
//
const menuHeight = menu?.getBoundingClientRect().height || fixedMaxHeight;
const spaceBelow = window.innerHeight - rect.bottom - padding;
const spaceAbove = rect.top - padding;
let top: number;
let maxHeight: number | undefined;
if (spaceBelow >= menuHeight) {
//
top = rect.bottom + gap;
} else if (spaceAbove >= menuHeight) {
//
top = rect.top - menuHeight - gap;
} else if (spaceBelow >= spaceAbove) {
//
const availableHeight = Math.max(80, spaceBelow - gap);
maxHeight = availableHeight;
top = rect.bottom + gap;
} else {
//
const availableHeight = Math.max(80, spaceAbove - gap);
maxHeight = availableHeight;
top = Math.max(padding, rect.top - availableHeight - gap);
}
floatingMenuStyle.value = {
position: 'fixed',
top: `${Math.round(top)}px`,
left: `${Math.round(left)}px`,
right: 'auto',
width: `${Math.round(menuWidth)}px`,
zIndex: '2147483647'
zIndex: '2147483647',
...(maxHeight !== undefined ? { maxHeight: `${Math.round(maxHeight)}px` } : {})
};
};
@ -3713,8 +3733,9 @@ const applyDefaultHideWorkspaceOption = async (hidden: boolean) => {
right: auto;
top: auto;
width: 300px;
max-height: min(420px, 60vh);
overflow: auto;
max-height: calc(44px * 4 + 12px);
overflow-y: auto;
overflow-x: hidden;
padding: 6px;
border-radius: 20px;
background: var(--settings-floating-menu-bg);

View File

@ -144,17 +144,23 @@ class TokenMixin:
return False
try:
success = self.conversation_manager.update_token_statistics(
# 路由到正确的 conversation_manager与 get_conversation_token_statistics 一致)
# 多智能体对话 ID 存储在 multi_agent_conversation_manager 中,
# 直接使用 self.conversation_manager 会找不到对话导致统计写入失败
target_manager = getattr(
self, "_get_conversation_manager_for_id", lambda _: self.conversation_manager
)(self.current_conversation_id)
success = target_manager.update_token_statistics(
self.current_conversation_id,
prompt_tokens,
completion_tokens,
total_tokens,
current_context_tokens=current_context_tokens,
)
if success:
self.safe_broadcast_token_update()
return success
except Exception as e:
print(f"更新usage统计失败: {e}")