From fc74e0d952b87374abf23b47166fbf401d041d5d Mon Sep 17 00:00:00 2001 From: kuaifan Date: Fri, 9 Jan 2026 15:17:21 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=A0=87=E7=AD=BE=E9=A1=B5=E6=8B=96?= =?UTF-8?q?=E6=8B=BD=E5=90=88=E5=B9=B6=E6=97=B6=E6=94=AF=E6=8C=81=E6=8F=92?= =?UTF-8?q?=E5=85=A5=E5=88=B0=E9=BC=A0=E6=A0=87=E6=89=80=E5=9C=A8=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - getAllWebTabWindowsInfo 增加返回 tabCount 用于计算标签位置 - attachToWindow 根据鼠标 screenX 和目标窗口标签信息计算插入位置 - 拖拽标签合并到其他窗口时插入到鼠标位置而非总在末尾 --- electron/electron.js | 3 ++- electron/render/tabs/index.html | 37 +++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/electron/electron.js b/electron/electron.js index fcd4b73a3..d36b02961 100644 --- a/electron/electron.js +++ b/electron/electron.js @@ -1532,7 +1532,8 @@ function getAllWebTabWindowsInfo() { y: bounds.y, width: bounds.width, height: webTabHeight - } + }, + tabCount: windowData.views.length }); } } diff --git a/electron/render/tabs/index.html b/electron/render/tabs/index.html index 344fed634..6559771c7 100644 --- a/electron/render/tabs/index.html +++ b/electron/render/tabs/index.html @@ -446,12 +446,41 @@ * 将标签附加到目标窗口 */ attachToWindow(tabId, targetWindowId, screenX) { - // 计算插入位置(可以根据 screenX 确定位置,这里简化处理) + // 查找目标窗口信息 + const targetWindow = this.otherWindows.find(w => w.windowId === targetWindowId) + let insertIndex = null + + if (targetWindow && targetWindow.tabCount > 0) { + // 计算插入位置 + // 导航区域宽度(macOS 约 140px,Windows 约 100px) + const navAreaWidth = navigator.platform.includes('Mac') ? 140 : 100 + const tabBarX = targetWindow.tabBarBounds.x + const tabBarWidth = targetWindow.tabBarBounds.width + const tabCount = targetWindow.tabCount + + // 标签区域的起始位置和宽度 + const tabAreaStartX = tabBarX + navAreaWidth + const tabAreaWidth = tabBarWidth - navAreaWidth - 150 // 减去右侧操作按钮区域 + + // 计算每个标签的平均宽度 + const tabWidth = Math.min(180, tabAreaWidth / tabCount) // 最大标签宽度 180px + + // 鼠标相对于标签区域起始位置的偏移 + const relativeX = screenX - tabAreaStartX + + if (relativeX <= 0) { + insertIndex = 0 + } else { + // 计算鼠标位于第几个标签位置 + insertIndex = Math.min(Math.floor(relativeX / tabWidth), tabCount) + } + } + this.sendMessage('webTabAttach', { sourceWindowId: this.windowId, - tabId: tabId, - targetWindowId: targetWindowId, - insertIndex: null // 追加到末尾 + tabId, + targetWindowId, + insertIndex }) },