Restore pre-text and post-text with Use as input and Details.

Library items already stored those fields, but Details showed one blob and Use as input left the form's empty pre/post in place.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-09-02 14:51:35 -05:00
co-authored by Cursor
parent c20229da0e
commit c4e18eeb2c
6 changed files with 58 additions and 37 deletions
+4
View File
@@ -23,6 +23,8 @@ export type LibraryStill = {
role?: 'input' | 'output'
name?: string
prompt?: string
promptPre?: string
promptPost?: string
familyId?: string
parentStillId?: string
chainIndex?: number
@@ -34,6 +36,8 @@ export type LibraryClip = {
folderId: string
name?: string
prompt: string
promptPre?: string
promptPost?: string
aspect: string
width: number
height: number
+11 -3
View File
@@ -33,6 +33,12 @@ export type StillGenerationSettings = {
export type SettingsRow = { label: string; value: string }
function pushPromptRows(rows: SettingsRow[], item: { prompt?: string; promptPre?: string; promptPost?: string }) {
if (item.promptPre?.trim()) rows.push({ label: 'Pre-text', value: item.promptPre.trim() })
if (item.prompt?.trim()) rows.push({ label: 'Prompt', value: item.prompt.trim() })
if (item.promptPost?.trim()) rows.push({ label: 'Post-text', value: item.promptPost.trim() })
}
function finiteNumber(raw: unknown): number | undefined {
const value = Number(raw)
return Number.isFinite(value) ? value : undefined
@@ -141,10 +147,10 @@ export function stillModeLabel(still: { filename?: string; settings?: StillGener
return ''
}
export function stillSettingsRows(still: { prompt?: string; width?: number; height?: number; settings?: StillGenerationSettings | null }) {
export function stillSettingsRows(still: { prompt?: string; promptPre?: string; promptPost?: string; width?: number; height?: number; settings?: StillGenerationSettings | null }) {
const settings = still.settings
const rows: SettingsRow[] = []
if (still.prompt?.trim()) rows.push({ label: 'Prompt', value: still.prompt.trim() })
pushPromptRows(rows, still)
const mode = stillModeLabel(still)
if (mode) rows.push({ label: 'Mode', value: mode })
if (!settings) return rows
@@ -203,6 +209,8 @@ function videoWorkflowLabel(workflow?: string) {
export function clipSettingsRows(clip: {
prompt?: string
promptPre?: string
promptPost?: string
width?: number
height?: number
duration?: number
@@ -220,7 +228,7 @@ export function clipSettingsRows(clip: {
loraStack?: LoraStackItem[]
}) {
const rows: SettingsRow[] = []
if (clip.prompt?.trim()) rows.push({ label: 'Prompt', value: clip.prompt.trim() })
pushPromptRows(rows, clip)
const workflow = videoWorkflowLabel(clip.workflow)
if (workflow) rows.push({ label: 'Workflow', value: workflow })
if (clip.width && clip.height) rows.push({ label: 'Size', value: `${clip.width}×${clip.height}` })
+25 -16
View File
@@ -19,24 +19,33 @@ export function applyPromptParts(parts: PromptParts, middle: string) {
return composePromptParts(parts.pre, middle, parts.post)
}
export function restorePromptParts(saved: string, stored?: Partial<PromptParts> | null, current?: Partial<PromptParts> | null): PromptParts {
function peelPromptWrappers(mid: string, pre: string, post: string) {
let next = sanitizePromptPart(mid)
if (pre && next.startsWith(pre)) next = next.slice(pre.length).replace(/^\n+/, '')
if (post && next.endsWith(post)) next = next.slice(0, Math.max(0, next.length - post.length)).replace(/\n+$/, '')
return next.trim()
}
export function restorePromptParts(saved: string, stored?: Partial<PromptParts> | null): PromptParts {
const pre = sanitizePromptPart(stored?.pre ?? '').trim()
const post = sanitizePromptPart(stored?.post ?? '').trim()
if (pre || post) {
return {
pre,
prompt: sanitizePromptPart(stored?.prompt ?? saved).trim() || sanitizePromptPart(saved).trim(),
post
}
}
let mid = sanitizePromptPart(stored?.prompt ?? saved)
const curPre = sanitizePromptPart(current?.pre || '').trim()
const curPost = sanitizePromptPart(current?.post || '').trim()
if (curPre && mid.startsWith(curPre)) mid = mid.slice(curPre.length).replace(/^\n+/, '')
if (curPost && mid.endsWith(curPost)) mid = mid.slice(0, Math.max(0, mid.length - curPost.length)).replace(/\n+$/, '')
return {
pre: current?.pre || '',
prompt: mid.trim(),
post: current?.post || ''
pre,
prompt: peelPromptWrappers(stored?.prompt ?? saved, pre, post),
post
}
}
export function formatPromptParts(
stored?: { prompt?: string; promptPre?: string; promptPost?: string } | null,
midOverride?: string
) {
const pre = sanitizePromptPart(stored?.promptPre || '').trim()
const post = sanitizePromptPart(stored?.promptPost || '').trim()
const prompt = peelPromptWrappers(midOverride ?? stored?.prompt ?? '', pre, post)
const blocks: string[] = []
if (pre) blocks.push(`Pre-text\n${pre}`)
if (prompt) blocks.push(pre || post ? `Prompt\n${prompt}` : prompt)
if (post) blocks.push(`Post-text\n${post}`)
return blocks.join('\n\n')
}