diff --git a/invokeai/frontend/web/src/features/stylePresets/util/getViewModeChunks.tsx b/invokeai/frontend/web/src/features/stylePresets/util/getViewModeChunks.tsx index 9cc015db03..d40333147f 100644 --- a/invokeai/frontend/web/src/features/stylePresets/util/getViewModeChunks.tsx +++ b/invokeai/frontend/web/src/features/stylePresets/util/getViewModeChunks.tsx @@ -1,13 +1,15 @@ import { PRESET_PLACEHOLDER } from 'features/stylePresets/hooks/usePresetModifiedPrompts'; + export const getViewModeChunks = (currentPrompt: string, presetPrompt?: string): [string, string, string] => { if (!presetPrompt || !presetPrompt.length) { return ['', currentPrompt, '']; } - const [firstPart, ...remainingParts] = presetPrompt.split(PRESET_PLACEHOLDER); - const chunks = [firstPart, remainingParts.join(PRESET_PLACEHOLDER)]; - if (chunks.filter((chunk) => chunk !== '').length === 1) { - return ['', currentPrompt, chunks[0] ?? '']; - } else { - return [chunks[0] ?? '', currentPrompt, chunks[1] ?? '']; + + const [before, after] = presetPrompt.split(PRESET_PLACEHOLDER, 2); + + if (!before || !after) { + return ['', `${currentPrompt} `, presetPrompt]; } + + return [before ?? '', currentPrompt, after ?? '']; };