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:
@@ -18,6 +18,7 @@ const upperBound = (offsets: ArrayLike<number>, target: number) => {
|
||||
export const stickyPromptFromViewport = (
|
||||
messages: readonly Msg[],
|
||||
offsets: ArrayLike<number>,
|
||||
bottom: number,
|
||||
top: number,
|
||||
sticky: boolean
|
||||
) => {
|
||||
@@ -26,8 +27,15 @@ export const stickyPromptFromViewport = (
|
||||
}
|
||||
|
||||
const first = Math.max(0, Math.min(messages.length - 1, upperBound(offsets, top) - 1))
|
||||
const last = Math.max(first, Math.min(messages.length - 1, upperBound(offsets, bottom) - 1))
|
||||
|
||||
for (let i = first; i >= 0; i--) {
|
||||
for (let i = first; i <= last; i++) {
|
||||
if (messages[i]?.role === 'user') {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = first - 1; i >= 0; i--) {
|
||||
if (messages[i]?.role !== 'user') {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user