Skip to content

Commit d15b6f8

Browse files
xesrevinuGit Agent
andcommitted
fix(shared): correct line counting and wrapping
- Fix line counting for trailing newline in text.ts - Respect width parameter in wrapExplanation instead of fixed 100 Fixes line counting when a string ends with a newline and makes wrapExplanation respect the width parameter rather than a hard coded value, improving text wrapping behavior. Co-Authored-By: Git Agent <noreply@git-agent.dev>
1 parent a4cf3c1 commit d15b6f8

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/shared/text.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const countLines = (content: string): number => {
44
if (content.length === 0) {
55
return 0;
66
}
7-
return content.split("\n").length - 1;
7+
return content.endsWith("\n") ? content.split("\n").length - 1 : content.split("\n").length;
88
};
99

1010
export const wrapLongLine = (line: string, width: number): Array<string> => {
@@ -33,7 +33,7 @@ export const wrapLongLine = (line: string, width: number): Array<string> => {
3333
export const wrapExplanation = (text: string, width = 72): string =>
3434
text
3535
.split("\n")
36-
.flatMap((line) => (line.length <= 100 ? [line] : wrapLongLine(line, width)))
36+
.flatMap((line) => (line.length <= width ? [line] : wrapLongLine(line, width)))
3737
.join("\n");
3838

3939
export const extractJson = (input: string): string => {

0 commit comments

Comments
 (0)