Tab korjaa kirjoitusvirheet + fuzzy-match alikomennoille
Tab-painallus yrittää ensin autokorjausta (typo-taulukko + Levenshtein), sitten normaalia tab-completionia. Myös alikomennot korjautuvat fuzzy-matchilla (esim. "kpn rnu" → "kpn run"). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2264,11 +2264,26 @@ Files: ${Object.keys(generatedFiles).join(', ')}`;
|
||||
}
|
||||
}
|
||||
// Levenshtein-etäisyys ensimmäiselle sanalle
|
||||
const firstWord = input.trim().split(/\s+/)[0].toLowerCase();
|
||||
const words = input.trim().split(/\s+/);
|
||||
const firstWord = words[0].toLowerCase();
|
||||
if (firstWord !== 'kpn' && firstWord.length >= 2 && firstWord.length <= 5) {
|
||||
const dist = levenshtein(firstWord, 'kpn');
|
||||
if (dist <= 2) return 'kpn' + input.slice(firstWord.length);
|
||||
}
|
||||
// Fuzzy-korjaus alikomentotasolla: "kpn rnu" → "kpn run"
|
||||
if (firstWord === 'kpn' && words.length >= 2) {
|
||||
const sub = words[1].toLowerCase();
|
||||
const subCommands = ['help', 'run', 'project', 'pipeline', 'load', 'status', 'models', 'hello', 'clear'];
|
||||
let bestMatch = null, bestDist = 3;
|
||||
for (const cmd of subCommands) {
|
||||
const d = levenshtein(sub, cmd);
|
||||
if (d > 0 && d < bestDist) { bestDist = d; bestMatch = cmd; }
|
||||
}
|
||||
if (bestMatch) {
|
||||
words[1] = bestMatch;
|
||||
return words.join(' ');
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2426,6 +2441,13 @@ Files: ${Object.keys(generatedFiles).join(', ')}`;
|
||||
};
|
||||
|
||||
function tabComplete(input) {
|
||||
// Autokorjaus ensin: korjaa typo ja palauta true jos korjattiin
|
||||
const corrected = autocorrect(input.value.trim());
|
||||
if (corrected && corrected !== input.value.trim()) {
|
||||
input.value = corrected;
|
||||
return true;
|
||||
}
|
||||
|
||||
const val = input.value;
|
||||
const words = val.trimEnd().split(/\s+/);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user