diff --git a/README.md b/README.md index 7c1dffe..47aeaf6 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,13 @@ The packaged applications will be available in the `release` directory. - Window remains invisible to specified screen sharing applications - Start a new problem using [Control or Cmd + R] +6. **Language Selection + + - Easily switch between programming languages with a single click + - Use arrow keys for keyboard navigation through available languages + - The system dynamically adapts to any languages added or removed from the codebase + - Your language preference is saved between sessions + ## Adding More AI Models This application is built with extensibility in mind. You can easily add support for additional LLMs alongside the existing OpenAI integration: diff --git a/src/components/Queue/QueueCommands.tsx b/src/components/Queue/QueueCommands.tsx index 1f8d471..88d6c28 100644 --- a/src/components/Queue/QueueCommands.tsx +++ b/src/components/Queue/QueueCommands.tsx @@ -1,4 +1,5 @@ import React, { useState, useEffect, useRef } from "react" +import { createRoot } from "react-dom/client" import { useToast } from "../../contexts/toast" import { LanguageSelector } from "../shared/LanguageSelector" @@ -23,6 +24,56 @@ const QueueCommands: React.FC = ({ const tooltipRef = useRef(null) const { showToast } = useToast() + // Extract the repeated language selection logic into a separate function + const extractLanguagesAndUpdate = (direction?: 'next' | 'prev') => { + // Create a hidden instance of LanguageSelector to extract languages + const hiddenRenderContainer = document.createElement('div'); + hiddenRenderContainer.style.position = 'absolute'; + hiddenRenderContainer.style.left = '-9999px'; + document.body.appendChild(hiddenRenderContainer); + + // Create a root and render the LanguageSelector temporarily + const root = createRoot(hiddenRenderContainer); + root.render( + {}} + /> + ); + + // Use a small delay to ensure the component has rendered + // 50ms is generally enough for React to complete a render cycle + setTimeout(() => { + // Extract options from the rendered select element + const selectElement = hiddenRenderContainer.querySelector('select'); + if (selectElement) { + const options = Array.from(selectElement.options); + const values = options.map(opt => opt.value); + + // Find current language index + const currentIndex = values.indexOf(currentLanguage); + let newIndex = currentIndex; + + if (direction === 'prev') { + // Go to previous language + newIndex = (currentIndex - 1 + values.length) % values.length; + } else { + // Default to next language + newIndex = (currentIndex + 1) % values.length; + } + + if (newIndex !== currentIndex) { + setLanguage(values[newIndex]); + window.electronAPI.updateConfig({ language: values[newIndex] }); + } + } + + // Clean up + root.unmount(); + document.body.removeChild(hiddenRenderContainer); + }, 50); + }; + useEffect(() => { let tooltipHeight = 0 if (tooltipRef.current && isTooltipVisible) { @@ -164,7 +215,7 @@ const QueueCommands: React.FC = ({ strokeLinejoin="round" className="w-3.5 h-3.5" > - + @@ -379,10 +430,31 @@ const QueueCommands: React.FC = ({ {/* Separator and Log Out */}
- + {/* Simplified Language Selector */} +
+
extractLanguagesAndUpdate('next')} + tabIndex={0} + onKeyDown={(e) => { + if (e.key === 'ArrowUp' || e.key === 'ArrowLeft') { + extractLanguagesAndUpdate('prev'); + } else if (e.key === 'ArrowDown' || e.key === 'ArrowRight') { + extractLanguagesAndUpdate('next'); + } + }} + > + Language +
+ {currentLanguage} +
+ + + +
+
+
+
{/* API Key Settings */}