From eaf62c349d90d7b30afa3bb368b9183a2e021b6a Mon Sep 17 00:00:00 2001 From: Matthew Breedlove Date: Mon, 18 Aug 2025 03:48:33 -0400 Subject: [PATCH] Fix for custom command edit / width / timeout keypresses not working --- package.json | 2 +- src/tui/components/ItemsEditor.tsx | 16 ++++++++-------- src/types/Widget.ts | 2 +- src/widgets/CustomCommand.tsx | 10 ++-------- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 32872e2..5d850cd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ccstatusline", - "version": "2.0.2", + "version": "2.0.3", "description": "A customizable status line formatter for Claude Code CLI", "module": "src/ccstatusline.ts", "type": "module", diff --git a/src/tui/components/ItemsEditor.tsx b/src/tui/components/ItemsEditor.tsx index 61942bb..1ba8b80 100644 --- a/src/tui/components/ItemsEditor.tsx +++ b/src/tui/components/ItemsEditor.tsx @@ -30,7 +30,7 @@ export interface ItemsEditorProps { export const ItemsEditor: React.FC = ({ widgets, onUpdate, onBack, lineNumber, settings }) => { const [selectedIndex, setSelectedIndex] = useState(0); const [moveMode, setMoveMode] = useState(false); - const [customEditorWidget, setCustomEditorWidget] = useState<{ widget: WidgetItem; impl: Widget } | null>(null); + const [customEditorWidget, setCustomEditorWidget] = useState<{ widget: WidgetItem; impl: Widget; action?: string } | null>(null); const separatorChars = ['|', '-', ',', ' ']; // Determine which item types are allowed based on settings @@ -278,14 +278,13 @@ export const ItemsEditor: React.FC = ({ widgets, onUpdate, onB const newWidgets = [...widgets]; newWidgets[selectedIndex] = updatedWidget; onUpdate(newWidgets); + } else if (widgetImpl.renderEditor) { + // If handleEditorAction returned null, open the editor + setCustomEditorWidget({ widget: currentWidget, impl: widgetImpl, action: matchedKeybind.action }); } } else if (widgetImpl.renderEditor) { - // Set the action on the widget if it supports it - if (widgetImpl.setEditorAction) { - widgetImpl.setEditorAction(matchedKeybind.action); - } - // Open the widget's custom editor - setCustomEditorWidget({ widget: currentWidget, impl: widgetImpl }); + // Open the widget's custom editor with the action + setCustomEditorWidget({ widget: currentWidget, impl: widgetImpl, action: matchedKeybind.action }); } } } @@ -364,7 +363,8 @@ export const ItemsEditor: React.FC = ({ widgets, onUpdate, onB return customEditorWidget.impl.renderEditor({ widget: customEditorWidget.widget, onComplete: handleEditorComplete, - onCancel: handleEditorCancel + onCancel: handleEditorCancel, + action: customEditorWidget.action }); } diff --git a/src/types/Widget.ts b/src/types/Widget.ts index 3f48093..23ab461 100644 --- a/src/types/Widget.ts +++ b/src/types/Widget.ts @@ -40,7 +40,6 @@ export interface Widget { renderEditor?(props: WidgetEditorProps): React.ReactElement | null; supportsRawValue(): boolean; supportsColors(item: WidgetItem): boolean; - setEditorAction?(action: string): void; handleEditorAction?(action: string, item: WidgetItem): WidgetItem | null; } @@ -48,6 +47,7 @@ export interface WidgetEditorProps { widget: WidgetItem; onComplete: (updatedWidget: WidgetItem) => void; onCancel: () => void; + action?: string; } export interface CustomKeybind { diff --git a/src/widgets/CustomCommand.tsx b/src/widgets/CustomCommand.tsx index 9026f7d..572c0a1 100644 --- a/src/widgets/CustomCommand.tsx +++ b/src/widgets/CustomCommand.tsx @@ -17,8 +17,6 @@ import type { } from '../types/Widget'; export class CustomCommandWidget implements Widget { - private currentAction: string = 'edit-command'; - getDefaultColor(): string { return 'white'; } getDescription(): string { return 'Executes a custom shell command and displays output'; } getDisplayName(): string { return 'Custom Command'; } @@ -46,10 +44,6 @@ export class CustomCommandWidget implements Widget { }; } - setEditorAction(action: string): void { - this.currentAction = action; - } - handleEditorAction(action: string, item: WidgetItem): WidgetItem | null { if (action === 'toggle-preserve') { return { ...item, preserveColors: !item.preserveColors }; @@ -119,7 +113,7 @@ export class CustomCommandWidget implements Widget { } renderEditor(props: WidgetEditorProps): React.ReactElement { - return ; + return ; } supportsRawValue(): boolean { return false; } @@ -131,7 +125,7 @@ export class CustomCommandWidget implements Widget { interface EditorMode { type: 'command' | 'width' | 'timeout' | null } -const CustomCommandEditor: React.FC = ({ widget, onComplete, onCancel, action }) => { +const CustomCommandEditor: React.FC = ({ widget, onComplete, onCancel, action }) => { const getMode = (): EditorMode['type'] => { switch (action) { case 'edit-command': return 'command';