Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ export const createCreateProcedures = () => {
type: "worktree",
branch,
name: input.name ?? branch,
isUnnamed: !input.name,
tabOrder: maxTabOrder + 1,
})
.returning()
Expand Down Expand Up @@ -591,6 +592,7 @@ export const createCreateProcedures = () => {
type: "worktree",
branch: worktree.branch,
name: input.name ?? worktree.branch,
isUnnamed: !input.name,
tabOrder: maxTabOrder + 1,
})
.returning()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export const createQueryProcedures = () => {
updatedAt: number;
lastOpenedAt: number;
isUnread: boolean;
isUnnamed: boolean;
}>;
}
>();
Expand Down Expand Up @@ -215,6 +216,7 @@ export const createQueryProcedures = () => {
type: workspace.type as "worktree" | "branch",
worktreePath,
isUnread: workspace.isUnread ?? false,
isUnnamed: workspace.isUnnamed ?? false,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const createStatusProcedures = () => {
id: z.string(),
patch: z.object({
name: z.string().optional(),
preserveUnnamedStatus: z.boolean().optional(),
}),
}),
)
Expand All @@ -75,7 +76,11 @@ export const createStatusProcedures = () => {
}

touchWorkspace(input.id, {
...(input.patch.name !== undefined && { name: input.patch.name }),
...(input.patch.name !== undefined && {
name: input.patch.name,
// Only mark as named if not preserving unnamed status
...(input.patch.preserveUnnamedStatus ? {} : { isUnnamed: false }),
}),
});

return { success: true };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export function touchWorkspace(
workspaceId: string,
additionalFields?: Partial<{
isUnread: boolean;
isUnnamed: boolean;
branch: string;
name: string;
}>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,40 @@ import type {
} from "./types";
import { shellEscapePaths } from "./utils";

const stripLeadingEmoji = (text: string) =>
text.trim().replace(/^[\p{Emoji}\p{Symbol}]\s*/u, "");

export const Terminal = ({ paneId, tabId, workspaceId }: TerminalProps) => {
const pane = useTabsStore((s) => s.panes[paneId]);
const paneInitialCommands = pane?.initialCommands;
const paneInitialCwd = pane?.initialCwd;
const clearPaneInitialData = useTabsStore((s) => s.clearPaneInitialData);

const { data: workspaceData } = electronTrpc.workspaces.get.useQuery(
{ id: workspaceId },
{ staleTime: 30_000 },
);
const isUnnamedRef = useRef(false);
isUnnamedRef.current = workspaceData?.isUnnamed ?? false;

const utils = electronTrpc.useUtils();
const updateWorkspace = electronTrpc.workspaces.update.useMutation({
onSuccess: () => {
utils.workspaces.getAllGrouped.invalidate();
utils.workspaces.get.invalidate({ id: workspaceId });
},
});

const renameUnnamedWorkspaceRef = useRef<(title: string) => void>(() => {});
renameUnnamedWorkspaceRef.current = (title: string) => {
const cleanedTitle = stripLeadingEmoji(title);
if (isUnnamedRef.current && cleanedTitle) {
updateWorkspace.mutate({
id: workspaceId,
patch: { name: cleanedTitle, preserveUnnamedStatus: true },
});
}
};
const terminalRef = useRef<HTMLDivElement>(null);
const xtermRef = useRef<XTerm | null>(null);
const fitAddonRef = useRef<FitAddon | null>(null);
Expand Down Expand Up @@ -260,6 +289,7 @@ export const Terminal = ({ paneId, tabId, workspaceId }: TerminalProps) => {
isAlternateScreenRef,
isBracketedPasteRef,
debouncedSetTabAutoTitleRef,
renameUnnamedWorkspaceRef,
handleTerminalFocusRef,
registerClearCallbackRef,
unregisterClearCallbackRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export interface UseTerminalLifecycleOptions {
isAlternateScreenRef: MutableRefObject<boolean>;
isBracketedPasteRef: MutableRefObject<boolean>;
debouncedSetTabAutoTitleRef: MutableRefObject<DebouncedTitleSetter>;
renameUnnamedWorkspaceRef: MutableRefObject<(title: string) => void>;
handleTerminalFocusRef: MutableRefObject<() => void>;
registerClearCallbackRef: MutableRefObject<RegisterCallback>;
unregisterClearCallbackRef: MutableRefObject<UnregisterCallback>;
Expand Down Expand Up @@ -173,6 +174,7 @@ export function useTerminalLifecycle({
isAlternateScreenRef,
isBracketedPasteRef,
debouncedSetTabAutoTitleRef,
renameUnnamedWorkspaceRef,
handleTerminalFocusRef,
registerClearCallbackRef,
unregisterClearCallbackRef,
Expand Down Expand Up @@ -466,6 +468,7 @@ export function useTerminalLifecycle({
const titleDisposable = xterm.onTitleChange((title) => {
if (title) {
debouncedSetTabAutoTitleRef.current(tabIdRef.current, title);
renameUnnamedWorkspaceRef.current(title);
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `workspaces` ADD `is_unnamed` integer DEFAULT false;
Loading