fix: prompt ghost enrichi (contexte phrase) + trim espaces au Tab
- Mid-word: prompt avec contexte de la phrase + exemple - acceptGhost: trim leading whitespace pour eviter double espace - Prompt plus direct pour le modele 1.5B
This commit is contained in:
@@ -1804,8 +1804,11 @@ body { font-family: var(--sans); background: var(--bg); color: var(--text); heig
|
|||||||
var start = ta.selectionStart;
|
var start = ta.selectionStart;
|
||||||
var before = ta.value.slice(0, start);
|
var before = ta.value.slice(0, start);
|
||||||
var after = ta.value.slice(start);
|
var after = ta.value.slice(start);
|
||||||
ta.value = before + _ghostText + after;
|
// Trim to avoid double spaces
|
||||||
ta.setSelectionRange(start + _ghostText.length, start + _ghostText.length);
|
var insert = _ghostText.replace(/^\s+/, '');
|
||||||
|
if (!insert) return;
|
||||||
|
ta.value = before + insert + after;
|
||||||
|
ta.setSelectionRange(start + insert.length, start + insert.length);
|
||||||
clearGhost();
|
clearGhost();
|
||||||
ta.focus();
|
ta.focus();
|
||||||
markDirty();
|
markDirty();
|
||||||
@@ -1816,17 +1819,19 @@ body { font-family: var(--sans); background: var(--bg); color: var(--text); heig
|
|||||||
function requestGhostCompletion() {
|
function requestGhostCompletion() {
|
||||||
var fullText = ta.value.slice(0, ta.selectionStart);
|
var fullText = ta.value.slice(0, ta.selectionStart);
|
||||||
if (fullText.trim().length < 1) return;
|
if (fullText.trim().length < 1) return;
|
||||||
// Detect context: mid-word vs end of phrase
|
|
||||||
var lastChar = fullText.slice(-1);
|
var lastChar = fullText.slice(-1);
|
||||||
var midWord = /[a-zA-Z0-9\u00C0-\u024F]$/.test(lastChar);
|
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;
|
var prompt, inputText;
|
||||||
if (midWord) {
|
if (midWord) {
|
||||||
var wordMatch = fullText.match(/([\w\u00C0-\u024F]+)$/);
|
var wordMatch = fullText.match(/([\w\u00C0-\u024F]+)$/);
|
||||||
var partialWord = wordMatch ? wordMatch[1] : fullText;
|
var partialWord = wordMatch ? wordMatch[1] : fullText;
|
||||||
inputText = partialWord;
|
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 {
|
} else {
|
||||||
inputText = fullText;
|
inputText = fullText;
|
||||||
prompt = 'Continue this text. Return ONLY the new text (do NOT repeat what is already written):\n' + 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) {
|
.then(function(data) {
|
||||||
var raw = (data.result || '').trim();
|
var raw = (data.result || '').trim();
|
||||||
if (!raw || raw.length < 1) return;
|
if (!raw || raw.length < 1) return;
|
||||||
// Strip any echoed input from the response
|
|
||||||
var prediction = raw;
|
var prediction = raw;
|
||||||
if (midWord && prediction.toLowerCase().startsWith(inputText.toLowerCase())) {
|
if (midWord && prediction.toLowerCase().startsWith(inputText.toLowerCase())) {
|
||||||
prediction = prediction.slice(inputText.length);
|
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.slice(inputText.length);
|
||||||
}
|
}
|
||||||
prediction = prediction.trim();
|
prediction = prediction.trim();
|
||||||
// Only show if prediction adds something meaningful
|
|
||||||
var alreadyThere = ta.value.slice(ta.selectionStart).trimStart();
|
var alreadyThere = ta.value.slice(ta.selectionStart).trimStart();
|
||||||
if (prediction && prediction.length > 0 && !alreadyThere.startsWith(prediction.slice(0, Math.min(6, prediction.length)))) {
|
if (prediction && prediction.length > 0 && !alreadyThere.startsWith(prediction.slice(0, Math.min(6, prediction.length)))) {
|
||||||
showGhost(prediction);
|
showGhost(prediction);
|
||||||
|
|||||||
Reference in New Issue
Block a user