From 043e35fbcea27a73b896d430338b0786fc777ee3 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Fri, 18 Jul 2025 14:04:55 +0000 Subject: [PATCH] refactor: extract repeated event value extraction pattern into helper function - Add extractEventValue helper function to reduce code duplication - Replace 5 occurrences of repeated pattern with helper function call - Improves code readability and maintainability Addresses ellipsi-bot feedback about repeated pattern: (e as unknown as CustomEvent)?.detail?.target?.value || ((e as any).target as HTMLTextAreaElement).value --- webview-ui/src/components/modes/ModesView.tsx | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/webview-ui/src/components/modes/ModesView.tsx b/webview-ui/src/components/modes/ModesView.tsx index 7c0c0719b5..973052fda6 100644 --- a/webview-ui/src/components/modes/ModesView.tsx +++ b/webview-ui/src/components/modes/ModesView.tsx @@ -63,6 +63,11 @@ function getGroupName(group: GroupEntry): ToolGroup { return Array.isArray(group) ? group[0] : group } +// Helper function to extract value from VSCode events (CustomEvent or regular Event) +function extractEventValue(e: Event | React.FormEvent): string { + return (e as unknown as CustomEvent)?.detail?.target?.value || ((e as any).target as HTMLTextAreaElement).value +} + const ModesView = ({ onDone }: ModesViewProps) => { const { t } = useAppTranslation() @@ -859,9 +864,7 @@ const ModesView = ({ onDone }: ModesViewProps) => { setLocalModeRoleDefinition(currentValue) }} onChange={(e) => { - const value = - (e as unknown as CustomEvent)?.detail?.target?.value || - ((e as any).target as HTMLTextAreaElement).value + const value = extractEventValue(e) setLocalModeRoleDefinition(value) }} onBlur={() => { @@ -942,9 +945,7 @@ const ModesView = ({ onDone }: ModesViewProps) => { setLocalModeDescription(currentValue || "") }} onChange={(e) => { - const value = - (e as unknown as CustomEvent)?.detail?.target?.value || - ((e as any).target as HTMLTextAreaElement).value + const value = extractEventValue(e) setLocalModeDescription(value) }} onBlur={() => { @@ -1026,9 +1027,7 @@ const ModesView = ({ onDone }: ModesViewProps) => { setLocalModeWhenToUse(currentValue || "") }} onChange={(e) => { - const value = - (e as unknown as CustomEvent)?.detail?.target?.value || - ((e as any).target as HTMLTextAreaElement).value + const value = extractEventValue(e) setLocalModeWhenToUse(value) }} onBlur={() => { @@ -1214,9 +1213,7 @@ const ModesView = ({ onDone }: ModesViewProps) => { setLocalModeCustomInstructions(currentValue || "") }} onChange={(e) => { - const value = - (e as unknown as CustomEvent)?.detail?.target?.value || - ((e as any).target as HTMLTextAreaElement).value + const value = extractEventValue(e) setLocalModeCustomInstructions(value) }} onBlur={() => { @@ -1431,9 +1428,7 @@ const ModesView = ({ onDone }: ModesViewProps) => { resize="vertical" value={customInstructions || ""} onChange={(e) => { - const value = - (e as unknown as CustomEvent)?.detail?.target?.value || - ((e as any).target as HTMLTextAreaElement).value + const value = extractEventValue(e) setCustomInstructions(value || undefined) vscode.postMessage({ type: "customInstructions",