nushell on your web browser
nushell wasm terminal

put cursor after where the completion happened instead of at the end of the prompt when completin

ptr.pet 7ee40d91 c6e4e970

verified
Changed files
+11 -9
www
src
+11 -9
www/src/main.ts
··· 247 247 cursorPos = (before + candidate.name).length; 248 248 }; 249 249 250 + const applyCompletionFromBase = (baseLine: string, candidate: Candidate) => { 251 + currentLine = getLineWithCompletion(baseLine, candidate); 252 + const before = baseLine.slice(0, candidate.span_start); 253 + cursorPos = (before + candidate.name).length; 254 + }; 255 + 250 256 const updateCompletionCandidates = async () => { 251 257 // Don't try to get completion if worker isn't loaded 252 258 if (!isWorkerReady) return; ··· 370 376 if (completionCandidates.length > 0) { 371 377 const cand = completionCandidates[completionIndex]; 372 378 if (cand) { 373 - currentLine = getLineWithCompletion(completionBaseLine, cand); 374 - cursorPos = currentLine.length; 379 + applyCompletionFromBase(completionBaseLine, cand); 375 380 } 376 381 } 377 382 ··· 516 521 (completionIndex - 1 + completionCandidates.length) % 517 522 completionCandidates.length; 518 523 const candidate = completionCandidates[completionIndex]; 519 - currentLine = getLineWithCompletion(completionBaseLine, candidate); 520 - cursorPos = currentLine.length; 524 + applyCompletionFromBase(completionBaseLine, candidate); 521 525 await refreshPrompt(); 522 526 break; 523 527 } ··· 547 551 if (completionCandidates.length > 0 && e === "\x1b[B") { 548 552 completionIndex = (completionIndex + 1) % completionCandidates.length; 549 553 const candidate = completionCandidates[completionIndex]; 550 - currentLine = getLineWithCompletion(completionBaseLine, candidate); 551 - cursorPos = currentLine.length; 554 + applyCompletionFromBase(completionBaseLine, candidate); 552 555 await refreshPrompt(); 553 556 break; 554 557 } ··· 583 586 (completionIndex + 1) % completionCandidates.length; 584 587 585 588 const candidate = completionCandidates[completionIndex]; 586 - currentLine = getLineWithCompletion(completionBaseLine, candidate); 589 + applyCompletionFromBase(completionBaseLine, candidate); 587 590 await refreshPrompt(); 588 591 } else { 589 592 // Guard: ensure worker is ready ··· 618 621 (completionIndex - 1 + completionCandidates.length) % 619 622 completionCandidates.length; 620 623 const candidate = completionCandidates[completionIndex]; 621 - currentLine = getLineWithCompletion(completionBaseLine, candidate); 622 - cursorPos = currentLine.length; 624 + applyCompletionFromBase(completionBaseLine, candidate); 623 625 await refreshPrompt(); 624 626 } 625 627 break;