From 8f80742ef197e71fc848fdf59768aadff5da5cce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20G=C3=B3mez?= Date: Fri, 19 Dec 2025 12:49:29 +0100 Subject: [PATCH] feat: tab names --- .prettierignore | 1 + src/components/TabBar.tsx | 109 ++++++++++++++++++++++++++++++++------ src/core/logic.ts | 34 ++++++++++++ src/core/state.ts | 7 +++ src/index.css | 4 +- 5 files changed, 137 insertions(+), 18 deletions(-) diff --git a/.prettierignore b/.prettierignore index 06accd0..b4ad061 100644 --- a/.prettierignore +++ b/.prettierignore @@ -3,3 +3,4 @@ node_modules .claude *.md package-lock.json +src/data/nostr-kinds-schema.yaml diff --git a/src/components/TabBar.tsx b/src/components/TabBar.tsx index 5ffdc6f..c5cded7 100644 --- a/src/components/TabBar.tsx +++ b/src/components/TabBar.tsx @@ -3,7 +3,7 @@ import { Button } from "./ui/button"; import { useGrimoire } from "@/core/state"; import { cn } from "@/lib/utils"; import { LayoutControls } from "./LayoutControls"; -import { useEffect } from "react"; +import { useEffect, useState } from "react"; export function TabBar() { const { @@ -11,13 +11,50 @@ export function TabBar() { setActiveWorkspace, createWorkspace, createWorkspaceWithNumber, + updateWorkspaceLabel, } = useGrimoire(); const { workspaces, activeWorkspaceId } = state; + // State for inline label editing + const [editingId, setEditingId] = useState(null); + const [editingLabel, setEditingLabel] = useState(""); + const handleNewTab = () => { createWorkspace(); }; + // Start editing a workspace label + const startEditing = (workspaceId: string, currentLabel?: string) => { + setEditingId(workspaceId); + setEditingLabel(currentLabel || ""); + }; + + // Save label changes + const saveLabel = () => { + if (editingId) { + updateWorkspaceLabel(editingId, editingLabel); + setEditingId(null); + setEditingLabel(""); + } + }; + + // Cancel editing + const cancelEditing = () => { + setEditingId(null); + setEditingLabel(""); + }; + + // Handle keyboard events in input + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === "Enter") { + e.preventDefault(); + saveLabel(); + } else if (e.key === "Escape") { + e.preventDefault(); + cancelEditing(); + } + }; + // Sort workspaces by number (for both rendering and keyboard shortcuts) const sortedWorkspaces = Object.values(workspaces).sort( (a, b) => a.number - b.number, @@ -62,22 +99,60 @@ export function TabBar() {
{/* Left side: Workspace tabs + new workspace button */}
- {sortedWorkspaces.map((ws) => ( - - ))} + {sortedWorkspaces.map((ws) => { + const isEditing = editingId === ws.id; + const isActive = ws.id === activeWorkspaceId; + + if (isEditing) { + // Render input field when editing + return ( +
e.stopPropagation()} + > + {ws.number} + setEditingLabel(e.target.value)} + onKeyDown={handleKeyDown} + onBlur={saveLabel} + autoFocus + style={{ width: `${Math.max(editingLabel.length, 1)}ch` }} + className="bg-transparent border-0 outline-none focus:outline-none focus:ring-0 p-0 m-0" + /> +
+ ); + } + + // Render button when not editing + return ( + + ); + })}