feat: allow close tab when mouse middle button click (#5347)

* 偏好设置增加鼠标中键关闭标签页的设置
This commit is contained in:
Netfan
2025-01-10 20:52:31 +08:00
committed by GitHub
parent 624beb6fa0
commit b8bffd884c
11 changed files with 55 additions and 1 deletions

View File

@@ -56,6 +56,20 @@ const tabsView = computed(() => {
} as TabConfig;
});
});
function onMouseDown(e: MouseEvent, tab: TabConfig) {
if (
e.button === 1 &&
tab.closable &&
!tab.affixTab &&
tabsView.value.length > 1 &&
props.middleClickToClose
) {
e.preventDefault();
e.stopPropagation();
emit('close', tab.key);
}
}
</script>
<template>
@@ -82,6 +96,7 @@ const tabsView = computed(() => {
class="tabs-chrome__item draggable translate-all group relative -mr-3 flex h-full select-none items-center"
data-tab-item="true"
@click="active = tab.key"
@mousedown="onMouseDown($event, tab)"
>
<VbenContextMenu
:handler-data="tab"

View File

@@ -62,6 +62,20 @@ const tabsView = computed(() => {
} as TabConfig;
});
});
function onMouseDown(e: MouseEvent, tab: TabConfig) {
if (
e.button === 1 &&
tab.closable &&
!tab.affixTab &&
tabsView.value.length > 1 &&
props.middleClickToClose
) {
e.preventDefault();
e.stopPropagation();
emit('close', tab.key);
}
}
</script>
<template>
@@ -85,6 +99,7 @@ const tabsView = computed(() => {
class="tab-item [&:not(.is-active)]:hover:bg-accent translate-all group relative flex cursor-pointer select-none"
data-tab-item="true"
@click="active = tab.key"
@mousedown="onMouseDown($event, tab)"
>
<VbenContextMenu
:handler-data="tab"

View File

@@ -33,6 +33,11 @@ export interface TabsProps {
* 仅限 tabs-chrome
*/
maxWidth?: number;
/**
* @zh_CN 点击中键时关闭Tab
*/
middleClickToClose?: boolean;
/**
* @zh_CN tab最小宽度
* 仅限 tabs-chrome
@@ -43,11 +48,11 @@ export interface TabsProps {
* @zh_CN 是否显示图标
*/
showIcon?: boolean;
/**
* @zh_CN 标签页风格
*/
styleType?: TabsStyleType;
/**
* @zh_CN 选项卡数据
*/