Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/formatters/helpers/getEndOfSection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,21 @@ test("getEndOfSection - capture to last line, shouldConsiderSubsections OFF", ()
expect(result).toBe(2);
});

test("getEndOfSection - target heading with only subsections, should not consider subsections", () => {
const lines = [
"## Insert", // target (0)
"1",
"2", // result (2)
"### Subsection",
"sub content",
];

const targetLine = 0;

const result = getEndOfSection(lines, targetLine, false);
expect(result).toBe(2);
});


test("getMarkdownHeadings - correctly identifies headings", () => {
const lines = [
Expand Down
6 changes: 2 additions & 4 deletions src/formatters/helpers/getEndOfSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,9 @@ function findNextHeading(
fromIdxInBody: number,
headings: Heading[],
): number | null {
const nextheading = headings.findIndex(
(heading) => heading.line > fromIdxInBody,
);
const nextHeading = headings.find((heading) => heading.line > fromIdxInBody);

return nextheading === -1 ? null : nextheading;
return nextHeading ? nextHeading.line : null;
}

function findPriorIdx<T>(
Expand Down