Skip to content

Commit 3408f1a

Browse files
authored
feat(app): add tab close keybind (#11780)
1 parent 34c58af commit 3408f1a

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

packages/app/src/components/session/session-sortable-tab.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import type { JSX } from "solid-js"
33
import { createSortable } from "@thisbeyond/solid-dnd"
44
import { FileIcon } from "@opencode-ai/ui/file-icon"
55
import { IconButton } from "@opencode-ai/ui/icon-button"
6-
import { Tooltip } from "@opencode-ai/ui/tooltip"
6+
import { TooltipKeybind } from "@opencode-ai/ui/tooltip"
77
import { Tabs } from "@opencode-ai/ui/tabs"
88
import { getFilename } from "@opencode-ai/util/path"
99
import { useFile } from "@/context/file"
1010
import { useLanguage } from "@/context/language"
11+
import { useCommand } from "@/context/command"
1112

1213
export function FileVisual(props: { path: string; active?: boolean }): JSX.Element {
1314
return (
@@ -27,6 +28,7 @@ export function FileVisual(props: { path: string; active?: boolean }): JSX.Eleme
2728
export function SortableTab(props: { tab: string; onTabClose: (tab: string) => void }): JSX.Element {
2829
const file = useFile()
2930
const language = useLanguage()
31+
const command = useCommand()
3032
const sortable = createSortable(props.tab)
3133
const path = createMemo(() => file.pathFromTab(props.tab))
3234
return (
@@ -36,15 +38,19 @@ export function SortableTab(props: { tab: string; onTabClose: (tab: string) => v
3638
<Tabs.Trigger
3739
value={props.tab}
3840
closeButton={
39-
<Tooltip value={language.t("common.closeTab")} placement="bottom">
41+
<TooltipKeybind
42+
title={language.t("common.closeTab")}
43+
keybind={command.keybind("tab.close")}
44+
placement="bottom"
45+
>
4046
<IconButton
4147
icon="close-small"
4248
variant="ghost"
4349
class="h-5 w-5"
4450
onClick={() => props.onTabClose(props.tab)}
4551
aria-label={language.t("common.closeTab")}
4652
/>
47-
</Tooltip>
53+
</TooltipKeybind>
4854
}
4955
hideCloseButton
5056
onMiddleClick={() => props.onTabClose(props.tab)}

packages/app/src/i18n/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const dict = {
4545
"command.session.new": "New session",
4646
"command.file.open": "Open file",
4747
"command.file.open.description": "Search files and commands",
48+
"command.tab.close": "Close tab",
4849
"command.context.addSelection": "Add selection to context",
4950
"command.context.addSelection.description": "Add selected lines from the current file",
5051
"command.terminal.toggle": "Toggle terminal",

packages/app/src/pages/session.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,18 @@ export default function Page() {
689689
slash: "open",
690690
onSelect: () => dialog.show(() => <DialogSelectFile onOpenFile={() => showAllFiles()} />),
691691
},
692+
{
693+
id: "tab.close",
694+
title: language.t("command.tab.close"),
695+
category: language.t("command.category.file"),
696+
keybind: "mod+w",
697+
disabled: !tabs().active(),
698+
onSelect: () => {
699+
const active = tabs().active()
700+
if (!active) return
701+
tabs().close(active)
702+
},
703+
},
692704
{
693705
id: "context.addSelection",
694706
title: language.t("command.context.addSelection"),

0 commit comments

Comments
 (0)