fixes #2578 use prompt bug on webkit browsers

This commit is contained in:
psychedelicious 2023-02-08 19:05:11 +11:00 committed by blessedcoolant
parent 0cee72dba5
commit 72357266a6
4 changed files with 20 additions and 11 deletions

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>InvokeAI - A Stable Diffusion Toolkit</title> <title>InvokeAI - A Stable Diffusion Toolkit</title>
<link rel="shortcut icon" type="icon" href="./assets/favicon-0d253ced.ico" /> <link rel="shortcut icon" type="icon" href="./assets/favicon-0d253ced.ico" />
<script type="module" crossorigin src="./assets/index-34c8aef8.js"></script> <script type="module" crossorigin src="./assets/index-4baf9db0.js"></script>
<link rel="stylesheet" href="./assets/index-b0bf79f4.css"> <link rel="stylesheet" href="./assets/index-b0bf79f4.css">
</head> </head>

View File

@ -5,15 +5,24 @@ export function getPromptAndNegative(input_prompt: InvokeAI.Prompt) {
let prompt: string = promptToString(input_prompt); let prompt: string = promptToString(input_prompt);
let negativePrompt: string | null = null; let negativePrompt: string | null = null;
const negativePromptRegExp = new RegExp(/(?<=\[)[^\][]*(?=])/, 'gi'); // Matches all negative prompts, 1st capturing group is the prompt itself
const negativePromptMatches = [...prompt.matchAll(negativePromptRegExp)]; const negativePromptRegExp = new RegExp(/\[([^\][]*)]/, 'gi');
if (negativePromptMatches && negativePromptMatches.length > 0) { // Grab the actual prompt matches (capturing group 1 is 1st index of match)
negativePrompt = negativePromptMatches.join(', '); const negativePromptMatches = [...prompt.matchAll(negativePromptRegExp)].map(
prompt = prompt (match) => match[1]
.replaceAll(negativePromptRegExp, '') );
.replaceAll('[]', '')
.trim(); if (negativePromptMatches.length) {
// Build the negative prompt itself
negativePrompt = negativePromptMatches.join(' ');
// Replace each match, including its surrounding brackets
// Remove each pair of empty brackets
// Trim whitespace
negativePromptMatches.forEach((match) => {
prompt = prompt.replace(`[${match}]`, '').replaceAll('[]', '').trim();
});
} }
return [prompt, negativePrompt]; return [prompt, negativePrompt];

File diff suppressed because one or more lines are too long