Skip to content

Commit aa192f5

Browse files
committed
fix: Enhance handling of empty input in formatPromptText function with trimSurroundingSpaces setting
1 parent 300ee91 commit aa192f5

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

web/js/auto-formatter.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,24 @@ export function formatPromptText(text) {
7676
// Handle null or undefined input
7777
if (text == null) return text;
7878

79-
// Trim surrounding spaces of the entire prompt if the setting is enabled
80-
if (settingValues.trimSurroundingSpaces) {
81-
text = text.trim();
79+
// If the text is empty or contains only spaces...
80+
if (text.trim().length === 0) {
81+
if (settingValues.trimSurroundingSpaces) {
82+
// ...And trimSurroundingSpaces is enabled, return an empty string
83+
return '';
84+
} else {
85+
// ...Otherwise, return the original text
86+
return text;
87+
}
8288
}
8389

84-
if (text.length === 0) return text;
90+
let processedText = text;
91+
if (settingValues.trimSurroundingSpaces) {
92+
processedText = text.trim();
93+
}
8594

8695
// Split text into individual lines for processing
87-
const lines = text.split('\n');
96+
const lines = processedText.split('\n');
8897
const formattedLines = [];
8998

9099
for (const line of lines) {

0 commit comments

Comments
 (0)