feat(ChannelTabs): Adds close tabs to the left (#38)

This commit is contained in:
Cater 2024-09-14 12:17:48 -04:00 committed by GitHub
parent d2220b637c
commit 5bb26ffab8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View file

@ -8,7 +8,7 @@ import { Margins } from "@utils/margins";
import { closeModal, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, openModal } from "@utils/modal";
import { Button, ChannelStore, FluxDispatcher, Forms, i18n, Menu, ReadStateStore, ReadStateUtils, Select, Text, TextInput, useState } from "@webpack/common";
import { bookmarkFolderColors, bookmarkPlaceholderName, closeOtherTabs, closeTab, closeTabsToTheRight, createTab, hasClosedTabs, isBookmarkFolder, openedTabs, reopenClosedTab, settings, toggleCompactTab } from "../util";
import { bookmarkFolderColors, bookmarkPlaceholderName, closeOtherTabs, closeTab, closeTabsToTheLeft, closeTabsToTheRight, createTab, hasClosedTabs, isBookmarkFolder, openedTabs, reopenClosedTab, settings, toggleCompactTab } from "../util";
import { Bookmark, BookmarkFolder, Bookmarks, ChannelTabsProps, UseBookmarkMethods } from "../util/types";
export function BasicContextMenu() {
@ -319,6 +319,12 @@ export function TabContextMenu({ tab }: { tab: ChannelTabsProps; }) {
disabled={openedTabs.indexOf(tab) === openedTabs.length - 1}
action={() => closeTabsToTheRight(tab.id)}
/>
<Menu.MenuItem
id="close-left-tabs"
label="Close Tabs to the Left"
disabled={openedTabs.indexOf(tab) === 0}
action={() => closeTabsToTheLeft(tab.id)}
/>
<Menu.MenuItem
id="reopen-closed-tab"
label="Reopen Closed Tab"

View file

@ -114,6 +114,19 @@ export function closeTabsToTheRight(id: number) {
else update();
}
export function closeTabsToTheLeft(id: number) {
const i = openTabs.findIndex(v => v.id === id);
if (i === -1) return logger.error("Couldn't find channel tab with ID " + id, openTabs);
const tabsToTheLeft = openTabs.filter((_, ind) => ind < i);
closedTabs.push(...tabsToTheLeft.reverse());
const tabsToTheRight = openTabs.filter((_, ind) => ind >= i);
replaceArray(openTabs, ...tabsToTheRight);
if (!tabsToTheRight.some(v => v.id === currentlyOpenTab)) moveToTab(openTabs[0].id);
else update();
}
export function handleChannelSwitch(ch: BasicChannelTabsProps) {
const tab = openTabs.find(c => c.id === currentlyOpenTab);
if (tab === undefined) return logger.error("Couldn't find the currently open channel " + currentlyOpenTab, openTabs);