diff --git a/frontend/editor-poc.html b/frontend/editor-poc.html
index 5eae16e..3295000 100644
--- a/frontend/editor-poc.html
+++ b/frontend/editor-poc.html
@@ -1804,8 +1804,11 @@ body { font-family: var(--sans); background: var(--bg); color: var(--text); heig
var start = ta.selectionStart;
var before = ta.value.slice(0, start);
var after = ta.value.slice(start);
- ta.value = before + _ghostText + after;
- ta.setSelectionRange(start + _ghostText.length, start + _ghostText.length);
+ // Trim to avoid double spaces
+ var insert = _ghostText.replace(/^\s+/, '');
+ if (!insert) return;
+ ta.value = before + insert + after;
+ ta.setSelectionRange(start + insert.length, start + insert.length);
clearGhost();
ta.focus();
markDirty();
@@ -1816,17 +1819,19 @@ body { font-family: var(--sans); background: var(--bg); color: var(--text); heig
function requestGhostCompletion() {
var fullText = ta.value.slice(0, ta.selectionStart);
if (fullText.trim().length < 1) return;
- // Detect context: mid-word vs end of phrase
var lastChar = fullText.slice(-1);
var midWord = /[a-zA-Z0-9\u00C0-\u024F]$/.test(lastChar);
- // For mid-word: extract the current word and ask AI to complete just it
var prompt, inputText;
if (midWord) {
var wordMatch = fullText.match(/([\w\u00C0-\u024F]+)$/);
var partialWord = wordMatch ? wordMatch[1] : fullText;
inputText = partialWord;
- prompt = 'Complete this word. Return ONLY the remaining letters (no spaces, no extra text): ' + partialWord;
+ // Provide surrounding context so the model can guess the word
+ var context = fullText.slice(0, -partialWord.length).trim();
+ prompt = 'Complete this French word. The word is: "' + partialWord +
+ '". Context: "' + (context || '(start of line)') +
+ '". Return ONLY the remaining letters of the word. Example: if word is "famil" return "ial" for "familial". Do NOT add spaces.';
} else {
inputText = fullText;
prompt = 'Continue this text. Return ONLY the new text (do NOT repeat what is already written):\n' + fullText;
@@ -1841,7 +1846,6 @@ body { font-family: var(--sans); background: var(--bg); color: var(--text); heig
.then(function(data) {
var raw = (data.result || '').trim();
if (!raw || raw.length < 1) return;
- // Strip any echoed input from the response
var prediction = raw;
if (midWord && prediction.toLowerCase().startsWith(inputText.toLowerCase())) {
prediction = prediction.slice(inputText.length);
@@ -1849,7 +1853,6 @@ body { font-family: var(--sans); background: var(--bg); color: var(--text); heig
prediction = prediction.slice(inputText.length);
}
prediction = prediction.trim();
- // Only show if prediction adds something meaningful
var alreadyThere = ta.value.slice(ta.selectionStart).trimStart();
if (prediction && prediction.length > 0 && !alreadyThere.startsWith(prediction.slice(0, Math.min(6, prediction.length)))) {
showGhost(prediction);