Skip to content

Commit

Permalink
Merge pull request #52 from MrEbbinghaus/master
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 committed Jul 21, 2022
2 parents ee2521b + 6f1cec5 commit a99f30f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/PageTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function isTabEqual(

interface TabsProps {
tabs: ITabInfo[];
showSingleTab: boolean;
activeTab: ITabInfo | null | undefined;
onClickTab: (tab: ITabInfo) => void;
onCloseTab: (tab: ITabInfo, force?: boolean) => void;
Expand All @@ -69,6 +70,7 @@ const Tabs = React.forwardRef<HTMLElement, TabsProps>(
activeTab,
onClickTab,
tabs,
showSingleTab,
onCloseTab,
onCloseAllTabs,
onPinTab,
Expand All @@ -89,7 +91,11 @@ const Tabs = React.forwardRef<HTMLElement, TabsProps>(
}, []);

const debouncedSwap = useDebounceFn(onSwapTab, 0);
const showTabs = showSingleTab || 0 < tabs.filter(tab => tab.pinned).length || 1 < tabs.length;

if (!showTabs) {
return null;
}
return (
<div
// @ts-expect-error ???
Expand Down Expand Up @@ -485,6 +491,7 @@ export function PageTabs(): JSX.Element {

const currActiveTabRef = React.useRef<ITabInfo | null>();
const latestTabsRef = useLatest(tabs);
const showSingleTab = logseq.settings["tabs:show-single-tab"];

const onCloseTab = useEventCallback((tab: ITabInfo, force?: boolean) => {
const idx = tabs.findIndex((t) => isTabEqual(t, tab));
Expand Down Expand Up @@ -667,6 +674,7 @@ export function PageTabs(): JSX.Element {
onClickTab={onChangeTab}
activeTab={activeTab}
tabs={tabs}
showSingleTab={showSingleTab}
onSwapTab={onSwapTab}
onPinTab={onPinTab}
onCloseTab={onCloseTab}
Expand Down
11 changes: 10 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const keyBindings = {
"tabs:select-prev": {
label: "Select Previous Tab",
binding: "ctrl+shift+tab",
},
}
};

const keybindingSettings: SettingSchemaDesc[] = Object.entries(keyBindings).map(
Expand All @@ -43,7 +43,16 @@ export const inheritCustomCSSSetting: SettingSchemaDesc = {
type: "boolean",
};

export const showSingleTab: SettingSchemaDesc = {
key: "tabs:show-single-tab",
title: "Show single tab?",
description: "When turned on the tab bar will only show if at least two tabs are open.",
type: "boolean",
default: true,
}

export const settings: SettingSchemaDesc[] = [
...keybindingSettings,
inheritCustomCSSSetting,
showSingleTab,
];

0 comments on commit a99f30f

Please sign in to comment.