fix(ai): live update for translation language input + preset sync
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 46s

This commit is contained in:
2026-05-03 01:42:22 +02:00
parent a7c3251b49
commit 635e516616
2 changed files with 54 additions and 3 deletions

View File

@@ -841,7 +841,7 @@ export function ContextualAIChat({
<button
key={l}
className={`text-xs px-2.5 py-1 rounded-lg border transition-colors ${translateTarget === l ? 'bg-primary text-primary-foreground border-primary' : 'bg-card border-border hover:bg-accent'}`}
onClick={() => setTranslateTarget(l)}
onClick={() => { setTranslateTarget(l); setCustomLangInput(l); }}
>{l}</button>
))}
</div>
@@ -849,8 +849,8 @@ export function ContextualAIChat({
className="text-xs px-3 py-1.5 rounded-lg border border-border bg-card outline-none focus:border-primary w-full"
placeholder={t('ai.action.customLang') || 'Autre langue...'}
value={customLangInput}
onChange={e => setCustomLangInput(e.target.value)}
onKeyDown={e => { if (e.key === 'Enter' && customLangInput.trim()) { setTranslateTarget(customLangInput.trim()); setCustomLangInput('') } }}
onChange={e => { const val = e.target.value; setCustomLangInput(val); setTranslateTarget(val); }}
onKeyDown={e => { if (e.key === 'Enter' && translateTarget.trim()) { handleAction(action, translateTarget.trim()); } }}
/>
<button
disabled={!!actionLoading || !translateTarget}

View File

@@ -0,0 +1,51 @@
const fs = require('fs');
const path = require('path');
const filePath = path.join(__dirname, '..', 'components', 'contextual-ai-chat.tsx');
let src = fs.readFileSync(filePath, 'utf8');
// Sync presets buttons
const OLD_PRESET_CLICK = `onClick={() => setTranslateTarget(l)}`;
const NEW_PRESET_CLICK = `onClick={() => { setTranslateTarget(l); setCustomLangInput(l); }}`;
if (src.includes(OLD_PRESET_CLICK)) {
src = src.replace(OLD_PRESET_CLICK, NEW_PRESET_CLICK);
console.log('Fix 1: Preset buttons sync updated');
} else {
console.error('Fix 1: OLD_PRESET_CLICK not found');
process.exit(1);
}
// Sync input and enable live update
const OLD_INPUT_LOGIC = `onChange={e => setCustomLangInput(e.target.value)}\r\n onKeyDown={e => { if (e.key === 'Enter' && customLangInput.trim()) { setTranslateTarget(customLangInput.trim()); setCustomLangInput('') } }}`;
// Fallback for different line endings if needed, but let's try matching a smaller part first
const OLD_ONCHANGE = `onChange={e => setCustomLangInput(e.target.value)}`;
const NEW_ONCHANGE = `onChange={e => { const val = e.target.value; setCustomLangInput(val); setTranslateTarget(val); }}`;
const OLD_ONKEYDOWN = `onKeyDown={e => { if (e.key === 'Enter' && customLangInput.trim()) { setTranslateTarget(customLangInput.trim()); setCustomLangInput('') } }}`;
const NEW_ONKEYDOWN = `onKeyDown={e => { if (e.key === 'Enter' && translateTarget.trim()) { handleAction(action, translateTarget.trim()); } }}`;
if (src.includes(OLD_ONCHANGE)) {
src = src.replace(OLD_ONCHANGE, NEW_ONCHANGE);
console.log('Fix 2: Input onChange updated');
} else {
console.error('Fix 2: OLD_ONCHANGE not found');
process.exit(1);
}
if (src.includes(OLD_ONKEYDOWN)) {
src = src.replace(OLD_ONKEYDOWN, NEW_ONKEYDOWN);
console.log('Fix 3: Input onKeyDown updated');
} else {
console.error('Fix 3: OLD_ONKEYDOWN not found');
// Try without \r if it failed
const altOnKeyDown = OLD_ONKEYDOWN.replace('\r\n', '\n');
if (src.includes(altOnKeyDown)) {
src = src.replace(altOnKeyDown, NEW_ONKEYDOWN);
console.log('Fix 3: Input onKeyDown updated (alt line ending)');
} else {
process.exit(1);
}
}
fs.writeFileSync(filePath, src);
console.log('Done!');