Clear pending ghost suggestions before writing the submit newline so inline hints do not appear in scrollback as typed input.

Add a regression test for submitting `ls` when history suggests `ls /bin`.
This commit is contained in:
Raven Scott
2026-04-25 03:30:56 -04:00
parent 9a41136aea
commit 95c60bb8bf
2 changed files with 59 additions and 1 deletions
+11 -1
View File
@@ -716,6 +716,14 @@ export async function createFishReadLine(ctx, { stdin, stdout, writeScreen }) {
inlineTabKeySig = ''
}
function clearGhostBeforeSubmit() {
clearGhostDebounce()
ghostRefreshSeq++
if (!ghost) return
ghost = ''
render()
}
function applyCurrentCompletionPick() {
const currentLine = lines[currentLineIndex] || ''
const cx = lastCompletionCx
@@ -1059,13 +1067,15 @@ export async function createFishReadLine(ctx, { stdin, stdout, writeScreen }) {
currentLineIndex++
cursor = 0
line = lines.join('\n')
clearGhostBeforeSubmit()
stdout.write('\n')
render()
return
}
stdout.write('\n')
const cmdToExec = lines.join('\n').trim()
clearGhostBeforeSubmit()
stdout.write('\n')
const resolve = pendingResolve
pendingResolve = null
historyIndex = -1
+48
View File
@@ -4870,6 +4870,54 @@ test('fish-readline ignores xterm focus in out CSI', async (t) => {
stdin.end()
})
test('fish-readline clears ghost hint before submit newline', async (t) => {
const stdin = new PassThrough()
stdin.isTTY = true
stdin.setRawMode = () => {}
const out = []
const stdout = {
columns: 120,
rows: 40,
write(s) {
out.push(String(s))
},
cursorTo() {},
clearLine() {}
}
const ctx = {
vfs: {
env: { USER: 'guest' },
getcwd: () => '/mnt/myPeers',
async readdir() {
return []
}
},
env: {},
b4a,
personalDrive: {
async get() {
return b4a.from('#1:ls /bin\n')
},
async put() {}
}
}
const rl = await createFishReadLine(ctx, { stdin, stdout })
const p = rl('> ')
stdin.write('ls\n')
t.is(await p, 'ls')
const newlineIndex = out.findIndex((s) => s === '\n')
t.ok(newlineIndex > 0)
const beforeSubmitNewline = out
.slice(0, newlineIndex)
.map(stripAnsi)
.filter(Boolean)
.at(-1)
t.is(beforeSubmitNewline.endsWith('> ls'), true)
t.absent(beforeSubmitNewline.includes('/bin'))
stdin.end()
})
test('fish-readline ^L emits xterm clear sequence', async (t) => {
const stdin = new PassThrough()
stdin.isTTY = true