feat: 标签页拖拽合并时支持插入到鼠标所在位置

- getAllWebTabWindowsInfo 增加返回 tabCount 用于计算标签位置
  - attachToWindow 根据鼠标 screenX 和目标窗口标签信息计算插入位置
  - 拖拽标签合并到其他窗口时插入到鼠标位置而非总在末尾
This commit is contained in:
kuaifan 2026-01-09 15:17:21 +00:00
parent 089f219280
commit fc74e0d952
2 changed files with 35 additions and 5 deletions

View File

@ -1532,7 +1532,8 @@ function getAllWebTabWindowsInfo() {
y: bounds.y,
width: bounds.width,
height: webTabHeight
}
},
tabCount: windowData.views.length
});
}
}

View File

@ -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 约 140pxWindows 约 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
})
},