From 68ea79002e20d0c65e7455640a75f2d29a797888 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 16 Sep 2022 18:34:31 +0300 Subject: [PATCH] Add option to drag-select tabs with middle click to close (#754) * Add option to drag-select tabs with middle click to close * Fixed typo --- src/_locales/dict.setup-page.ts | 12 ++++++++++- src/defaults/settings.ts | 1 + src/page.setup/components/settings.mouse.vue | 7 ++++++- src/sidebar/components/tab.vue | 22 ++++++++++++++++++-- src/types/settings.ts | 1 + 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/_locales/dict.setup-page.ts b/src/_locales/dict.setup-page.ts index f90c5a580..b39bd3627 100644 --- a/src/_locales/dict.setup-page.ts +++ b/src/_locales/dict.setup-page.ts @@ -2338,6 +2338,16 @@ export const setupPageTranslations: Translations = { ru: 'Только для несистемного контекстного меню', de: 'Nur bei nicht-nativem Kontextmenü', }, + 'settings.multiple_middle_close': { + en: 'Use multi-selection when closing tabs using middle-click', + ru: 'Использовать множественный выбор при закрытии вкладок средней кнопкой мыши', + de: 'Verwenden Sie die Mehrfachauswahl, wenn Sie Tabs mit einem Mittelklick schließen', + }, + 'settings.multiple_middle_close_note': { + en: 'Selected tabs will be closed on releasing the button', + ru: 'Выбранные вкладки будут закрыты при отпускании кнопки', + de: 'Ausgewählte Registerkarten werden beim Loslassen der Schaltfläche geschlossen', + }, 'settings.long_click_delay': { en: 'Long click delay (ms)', ru: 'Задержка длительного нажатия (мс)', @@ -3256,7 +3266,7 @@ export const setupPageTranslations: Translations = { }, 'styles.css_placeholder': { en: 'Write custom CSS here...', - ru: 'Write custom CSS here...', + ru: 'Вводите правила CSS здесь...', de: 'Eigenes CSS hier schreiben...', zh_CN: '在此处编写自定义 CSS...', }, diff --git a/src/defaults/settings.ts b/src/defaults/settings.ts index cc41451d5..da47ea3b4 100644 --- a/src/defaults/settings.ts +++ b/src/defaults/settings.ts @@ -143,6 +143,7 @@ export const DEFAULT_SETTINGS: SettingsState = { scrollThroughTabsCyclic: false, scrollThroughTabsScrollArea: 0, autoMenuMultiSel: true, + multipleMiddleClose: false, longClickDelay: 500, wheelThreshold: false, wheelThresholdX: 10, diff --git a/src/page.setup/components/settings.mouse.vue b/src/page.setup/components/settings.mouse.vue index 1156cd9f2..45894d3f0 100644 --- a/src/page.setup/components/settings.mouse.vue +++ b/src/page.setup/components/settings.mouse.vue @@ -48,6 +48,11 @@ section(ref="el") v-model:value="Settings.state.autoMenuMultiSel" :note="translate('settings.auto_menu_multi_sel_note')" @update:value="Settings.saveDebounced(150)") + ToggleField( + label="settings.multiple_middle_close" + v-model:value="Settings.state.multipleMiddleClose" + :note="translate('settings.multiple_middle_close_note')" + @update:value="Settings.saveDebounced(150)") NumField.-inline( label="settings.long_click_delay" unitLabel="settings.long_click_delay_" @@ -174,7 +179,7 @@ section(ref="el") :opts="Settings.getOpts('tabsPanelMiddleClickAction')" :folded="true" @update:value="Settings.saveDebounced(150)") - + .sub-title {{translate('settings.mouse.bookmarks_title')}} SelectField( label="settings.mouse.bookmarks.left_click_action" diff --git a/src/sidebar/components/tab.vue b/src/sidebar/components/tab.vue index 92d233efc..8b750f3b2 100644 --- a/src/sidebar/components/tab.vue +++ b/src/sidebar/components/tab.vue @@ -196,9 +196,14 @@ function onMouseDown(e: MouseEvent): void { // Middle else if (e.button === 1) { e.preventDefault() - Tabs.removeTabs([props.tab.id]) Mouse.blockWheel() - Selection.resetSelection() + if (Settings.state.multipleMiddleClose) { + Selection.resetSelection() + Mouse.startMultiSelection(e, props.tab.id) + } else { + Tabs.removeTabs([props.tab.id]) + Selection.resetSelection() + } } // Right @@ -239,6 +244,19 @@ function onMouseUp(e: MouseEvent): void { } } activating = false + } else if (e.button === 1) { + if (!Settings.state.multipleMiddleClose) return; + + const inMultiSelectionMode = Mouse.multiSelectionMode + Mouse.stopMultiSelection() + + if (inMultiSelectionMode && !Settings.state.autoMenuMultiSel && Selection.getLength() > 1) { + return + } + + if (!Selection.isSet()) select() + Tabs.removeTabs(Selection.get()) + } else if (e.button === 2) { if (e.ctrlKey || e.shiftKey) return diff --git a/src/types/settings.ts b/src/types/settings.ts index b1fa1a34c..6cec4216f 100644 --- a/src/types/settings.ts +++ b/src/types/settings.ts @@ -146,6 +146,7 @@ export interface SettingsState { scrollThroughTabsCyclic: boolean scrollThroughTabsScrollArea: number autoMenuMultiSel: boolean + multipleMiddleClose: boolean longClickDelay: number wheelThreshold: boolean wheelThresholdX: number