refactor: share terminal note wrapping

This commit is contained in:
Peter Steinberger 2026-03-14 00:53:35 +00:00
parent 827b166bbc
commit f7f5c24786
1 changed files with 29 additions and 12 deletions

View File

@ -54,6 +54,21 @@ function isCopySensitiveToken(word: string): boolean {
return word.includes("_") && FILE_LIKE_RE.test(word); return word.includes("_") && FILE_LIKE_RE.test(word);
} }
function pushWrappedWordSegments(params: {
word: string;
available: number;
firstPrefix: string;
continuationPrefix: string;
lines: string[];
}) {
const parts = splitLongWord(params.word, params.available);
const first = parts.shift() ?? "";
params.lines.push(params.firstPrefix + first);
for (const part of parts) {
params.lines.push(params.continuationPrefix + part);
}
}
function wrapLine(line: string, maxWidth: number): string[] { function wrapLine(line: string, maxWidth: number): string[] {
if (line.trim().length === 0) { if (line.trim().length === 0) {
return [line]; return [line];
@ -80,14 +95,15 @@ function wrapLine(line: string, maxWidth: number): string[] {
current = word; current = word;
continue; continue;
} }
const parts = splitLongWord(word, available); pushWrappedWordSegments({
const first = parts.shift() ?? ""; word,
lines.push(prefix + first); available,
firstPrefix: prefix,
continuationPrefix: nextPrefix,
lines,
});
prefix = nextPrefix; prefix = nextPrefix;
available = nextWidth; available = nextWidth;
for (const part of parts) {
lines.push(prefix + part);
}
continue; continue;
} }
current = word; current = word;
@ -109,12 +125,13 @@ function wrapLine(line: string, maxWidth: number): string[] {
current = word; current = word;
continue; continue;
} }
const parts = splitLongWord(word, available); pushWrappedWordSegments({
const first = parts.shift() ?? ""; word,
lines.push(prefix + first); available,
for (const part of parts) { firstPrefix: prefix,
lines.push(prefix + part); continuationPrefix: prefix,
} lines,
});
current = ""; current = "";
continue; continue;
} }