Skip to content

Commit a10759d

Browse files
Copilotalexr00
andcommitted
Fix unwrapping of non-indented list continuations
When a list item is followed by a wrapped line that has no indentation (but is not itself a list item), the line should be joined to the previous list item. This is common in commit messages wrapped at 72 chars. The fix moves the handling of non-indented continuations BEFORE calling getActiveListContentIndent, which was clearing the list stack and preventing the join from happening. Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 3b8286a commit a10759d

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

src/github/folderRepositoryManager.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3221,6 +3221,64 @@ function unwrapCommitMessageBody(body: string): string {
32213221
continue;
32223222
}
32233223

3224+
// Handle non-indented lines that should be joined to a previous list item
3225+
// This happens when commit messages are wrapped at 72 characters
3226+
// Check this BEFORE calling getActiveListContentIndent which would clear the stack
3227+
if (listStack.length > 0 && lineIndent === 0 && !LIST_ITEM_PATTERN.test(line)) {
3228+
const isBlockquote = BLOCKQUOTE_PATTERN.test(line);
3229+
if (!isBlockquote) {
3230+
const baseIndex = result.length - 1;
3231+
const baseLine = baseIndex >= 0 ? result[baseIndex] : '';
3232+
const previousLineIsBlank = baseLine.trim() === '';
3233+
3234+
if (!previousLineIsBlank && baseIndex >= 0) {
3235+
// Join this line and any following non-list-item lines with the previous list item
3236+
let joinedLine = baseLine;
3237+
let currentIndex = i;
3238+
3239+
while (currentIndex < lines.length) {
3240+
const currentLine = lines[currentIndex];
3241+
const trimmed = currentLine.trim();
3242+
3243+
// Stop at blank lines
3244+
if (!trimmed) {
3245+
break;
3246+
}
3247+
3248+
// Stop at list items
3249+
if (LIST_ITEM_PATTERN.test(currentLine)) {
3250+
break;
3251+
}
3252+
3253+
// Stop at blockquotes or fences
3254+
if (BLOCKQUOTE_PATTERN.test(currentLine) || FENCE_PATTERN.test(currentLine)) {
3255+
break;
3256+
}
3257+
3258+
// Stop at indented code blocks
3259+
const currentLineIndent = getLeadingWhitespaceLength(currentLine);
3260+
if (currentLineIndent >= 4) {
3261+
break;
3262+
}
3263+
3264+
// Stop if previous line has hard line break
3265+
if (hasHardLineBreak(joinedLine)) {
3266+
break;
3267+
}
3268+
3269+
joinedLine = appendWithSpace(joinedLine, trimmed);
3270+
currentIndex++;
3271+
}
3272+
3273+
if (currentIndex > i) {
3274+
result[baseIndex] = joinedLine;
3275+
i = currentIndex;
3276+
continue;
3277+
}
3278+
}
3279+
}
3280+
}
3281+
32243282
const activeContentIndent = getActiveListContentIndent(lineIndent);
32253283
const codeIndentThreshold = activeContentIndent !== undefined ? activeContentIndent + 4 : 4;
32263284
const isBlockquote = BLOCKQUOTE_PATTERN.test(line);

0 commit comments

Comments
 (0)