Skip to content

Commit c99bd48

Browse files
authored
new keybindng F2 to edit the active tab name, also fix refocus after name editing (#3158)
1 parent 02b9e5f commit c99bd48

File tree

6 files changed

+37
-0
lines changed

6 files changed

+37
-0
lines changed

docs/docs/keybindings.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ title: "Key Bindings"
66

77
import { Kbd, KbdChord } from "@site/src/components/kbd";
88
import { PlatformProvider, PlatformSelectorButton } from "@site/src/components/platformcontext";
9+
import { VersionBadge } from "@site/src/components/versionbadge";
910

1011
<PlatformProvider>
1112

@@ -44,6 +45,7 @@ Chords are shown with a + between the keys. You have 2 seconds to hit the 2nd ch
4445
| <Kbd k="Ctrl:Shift:1-9"/> | Switch to block number |
4546
| <Kbd k="Ctrl:Shift:Arrows"/> / <Kbd k="Ctrl:Shift:h/j/k/l"/> | Move left, right, up, down between blocks |
4647
| <Kbd k="Ctrl:Shift:x"/> | Replace the current block with a launcher block |
48+
| <Kbd k="F2"/> | Rename the current tab <VersionBadge version="v0.15" /> |
4749
| <Kbd k="Cmd:1-9"/> | Switch to tab number |
4850
| <Kbd k="Cmd:["/> / <Kbd k="Shift:Cmd:["/> | Switch tab left |
4951
| <Kbd k="Cmd:]"/> / <Kbd k="Shift:Cmd:]"/> | Switch tab right |

frontend/app/store/keymodel.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,14 @@ function registerGlobalKeys() {
634634
);
635635
return true;
636636
});
637+
globalKeyMap.set("F2", () => {
638+
const tabModel = getActiveTabModel();
639+
if (tabModel?.startRenameCallback != null) {
640+
tabModel.startRenameCallback();
641+
return true;
642+
}
643+
return false;
644+
});
637645
globalKeyMap.set("Cmd:g", () => {
638646
const bcm = getBlockComponentModel(getFocusedBlockInStaticTab());
639647
if (bcm.openSwitchConnection != null) {

frontend/app/store/tab-model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class TabModel {
2121
tabNumBlocksAtom: Atom<number>;
2222
isTermMultiInput = atom(false) as PrimitiveAtom<boolean>;
2323
metaCache: Map<string, Atom<any>> = new Map();
24+
startRenameCallback: (() => void) | null = null;
2425

2526
constructor(tabId: string, waveEnv?: TabModelEnv) {
2627
this.tabId = tabId;

frontend/app/tab/tab.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import { getTabBadgeAtom } from "@/app/store/badge";
55
import { refocusNode } from "@/app/store/global";
6+
import { getTabModelByTabId } from "@/app/store/tab-model";
67
import { TabRpcClient } from "@/app/store/wshrpcutil";
78
import { WaveEnv, WaveEnvSubset, useWaveEnv } from "@/app/waveenv/waveenv";
89
import { Button } from "@/element/button";
@@ -251,6 +252,7 @@ const TabInner = forwardRef<HTMLDivElement, TabProps>((props, ref) => {
251252

252253
const loadedRef = useRef(false);
253254
const renameRef = useRef<(() => void) | null>(null);
255+
const tabModel = getTabModelByTabId(id, env);
254256

255257
useEffect(() => {
256258
if (!loadedRef.current) {
@@ -259,6 +261,16 @@ const TabInner = forwardRef<HTMLDivElement, TabProps>((props, ref) => {
259261
}
260262
}, [onLoaded]);
261263

264+
useEffect(() => {
265+
const cb = () => renameRef.current?.();
266+
tabModel.startRenameCallback = cb;
267+
return () => {
268+
if (tabModel.startRenameCallback === cb) {
269+
tabModel.startRenameCallback = null;
270+
}
271+
};
272+
}, [tabModel]);
273+
262274
const handleTabClick = () => {
263275
onSelect();
264276
};

frontend/app/tab/vtab.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2026, Command Line Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
import { refocusNode } from "@/app/store/global";
45
import { validateCssColor } from "@/util/color-validator";
56
import { cn } from "@/util/util";
67
import { useCallback, useEffect, useRef, useState } from "react";
@@ -122,6 +123,7 @@ export function VTab({
122123
if (newText !== originalName) {
123124
onRename?.(newText);
124125
}
126+
setTimeout(() => refocusNode(null), 10);
125127
};
126128

127129
const handleKeyDown: React.KeyboardEventHandler<HTMLDivElement> = (event) => {

frontend/app/tab/vtabbar.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import { Tooltip } from "@/app/element/tooltip";
55
import { getTabBadgeAtom } from "@/app/store/badge";
6+
import { getTabModelByTabId } from "@/app/store/tab-model";
67
import { makeORef } from "@/app/store/wos";
78
import { TabRpcClient } from "@/app/store/wshrpcutil";
89
import { useWaveEnv } from "@/app/waveenv/waveenv";
@@ -121,6 +122,17 @@ function VTabWrapper({
121122
const [tabData] = env.wos.useWaveObjectValue<Tab>(makeORef("tab", tabId));
122123
const badges = useAtomValue(getTabBadgeAtom(tabId, env));
123124
const renameRef = useRef<(() => void) | null>(null);
125+
const tabModel = getTabModelByTabId(tabId, env);
126+
127+
useEffect(() => {
128+
const cb = () => renameRef.current?.();
129+
tabModel.startRenameCallback = cb;
130+
return () => {
131+
if (tabModel.startRenameCallback === cb) {
132+
tabModel.startRenameCallback = null;
133+
}
134+
};
135+
}, [tabModel]);
124136

125137
const rawFlagColor = tabData?.meta?.["tab:flagcolor"];
126138
let flagColor: string | null = null;

0 commit comments

Comments
 (0)