fix(ui-tui): hide stale sticky prompt when newer prompt is visible
Sticky prompt selection only considered the top edge of the viewport, so it could keep showing an older user prompt even when a newer one was already visible lower down. Suppress sticky output whenever a user message is visible in the viewport and cover it with a regression test.
This commit is contained in:
31
ui-tui/src/__tests__/viewport.test.ts
Normal file
31
ui-tui/src/__tests__/viewport.test.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { stickyPromptFromViewport } from '../domain/viewport.js'
|
||||
|
||||
describe('stickyPromptFromViewport', () => {
|
||||
it('hides the sticky prompt when a newer user message is already visible', () => {
|
||||
const messages = [
|
||||
{ role: 'user' as const, text: 'older prompt' },
|
||||
{ role: 'assistant' as const, text: 'older answer' },
|
||||
{ role: 'user' as const, text: 'current prompt' },
|
||||
{ role: 'assistant' as const, text: 'current answer' }
|
||||
]
|
||||
|
||||
const offsets = [0, 2, 10, 12, 20]
|
||||
|
||||
expect(stickyPromptFromViewport(messages, offsets, 16, 8, false)).toBe('')
|
||||
})
|
||||
|
||||
it('shows the latest user message above the viewport when no user message is visible', () => {
|
||||
const messages = [
|
||||
{ role: 'user' as const, text: 'older prompt' },
|
||||
{ role: 'assistant' as const, text: 'older answer' },
|
||||
{ role: 'user' as const, text: 'current prompt' },
|
||||
{ role: 'assistant' as const, text: 'current answer' }
|
||||
]
|
||||
|
||||
const offsets = [0, 2, 10, 12, 20]
|
||||
|
||||
expect(stickyPromptFromViewport(messages, offsets, 20, 16, false)).toBe('current prompt')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user