fix: smart separator respects existing punctuation

Don't add '.' if prompt already ends with punctuation (.!?,;:).
Logic: endsWithPunct || startsLower = just space, otherwise '. '
Prevents double-period '..' on continuation join.
This commit is contained in:
rin.kagamine committed 2026-05-31 10:50:02 -04:00
1 parent 050c104201
commit b86b4e5011
1 file changed
+7 -4
+7 -4
View File
@@ -192,10 +192,12 @@ export default function Generator({ onGenerate }: Props) {
// Append continuation to existing prompt // Append continuation to existing prompt
setPrompt(prev => { setPrompt(prev => {
const trimmed = prev.trimEnd() const trimmed = prev.trimEnd()
// If result starts lowercase, it flows from the input — just space const endsWithPunct = /[.!?,;:]$/.test(trimmed)
// If result starts uppercase, treat as new sentence — period + space
const startsLower = /^[a-z]/.test(result) const startsLower = /^[a-z]/.test(result)
const separator = startsLower ? ' ' : '. ' // Already punctuated? Just space.
// Flows naturally (lowercase)? Just space.
// Otherwise: period + space for a new sentence.
const separator = (endsWithPunct || startsLower) ? ' ' : '. '
return trimmed + separator + result return trimmed + separator + result
}) })
} else { } else {
@@ -229,8 +231,9 @@ export default function Generator({ onGenerate }: Props) {
// Fallback: append to additional field // Fallback: append to additional field
setStructuredPrompt(prev => { setStructuredPrompt(prev => {
const existing = prev.additional?.trim() || '' const existing = prev.additional?.trim() || ''
const endsWithPunct = /[.!?,;:]$/.test(existing)
const startsLower = /^[a-z]/.test(result) const startsLower = /^[a-z]/.test(result)
const separator = startsLower ? ' ' : '. ' const separator = (endsWithPunct || startsLower) ? ' ' : '. '
return { ...prev, additional: existing + separator + result } return { ...prev, additional: existing + separator + result }
}) })
} else { } else {