diff --git a/javascript/prompt_format.js b/javascript/prompt_format.js index ffbc4ac..4eabc84 100644 --- a/javascript/prompt_format.js +++ b/javascript/prompt_format.js @@ -281,6 +281,7 @@ class LeFormatter { for (const field of config.promptFields) { field.addEventListener('paste', (event) => { + /** @type {string} */ let paste = (event.clipboardData || window.clipboardData).getData('text'); if ([...paste.matchAll(paramPatterns)].length > 3) return; // Infotext @@ -290,6 +291,8 @@ class LeFormatter { const commaStart = paste.match(/^\s*\,/); const commaEnd = paste.match(/\,\s*$/); + const multiline = !paste.includes(","); + if (config.booru) { paste = paste.replace(/\s*[\d.]+[kM]\s*|\s*[\d]{3,}\s*|[\?\+\-]\s+/g, ", "); for (const excl of ["Artist", "Characters", "Character", "Copyright", "Tags", "Tag", "General"]) @@ -301,7 +304,14 @@ class LeFormatter { }); } - paste = LeFormatter.formatString(paste, config.dedupe, config.removeUnderscore); + if (multiline) { + const lines = []; + for (const line of paste.split("\n")) + lines.push(LeFormatter.formatString(line, config.dedupe, config.removeUnderscore)); + paste = lines.join("\n"); + } else + paste = LeFormatter.formatString(paste, config.dedupe, config.removeUnderscore); + paste = `${commaStart ? ", " : ""}${paste}${commaEnd ? ", " : ""}` const currentText = field.value;