MCPcopy Create free account
hub / github.com/banga/git-split-diffs / pushWord

Function pushWord

src/wrapSpannedStringByWord.ts:27–58  ·  view source on GitHub ↗
(startIndex: number, endIndex: number)

Source from the content-addressed store, hash-verified

25 }
26
27 function pushWord(startIndex: number, endIndex: number) {
28 let wordWidth = 0;
29 for (let i = startIndex; i < endIndex; i++) {
30 wordWidth += charWidths[i];
31 }
32
33 // word can fit on current line
34 if (wordWidth <= budget) {
35 curLineEnd = endIndex;
36 budget -= wordWidth;
37 return;
38 }
39
40 // word can fit in the new line, so start a new one
41 if (wordWidth <= width) {
42 flushLine();
43 curLineEnd = endIndex;
44 budget -= wordWidth;
45 return;
46 }
47
48 // word is too long to fit in any line, so lets break it and push each
49 // part
50 for (let i = startIndex; i < endIndex; i++) {
51 const charLength = charWidths[i];
52 if (budget < charLength) {
53 flushLine();
54 }
55 budget -= charLength;
56 curLineEnd++;
57 }
58 }
59
60 let prevIndex = 0;
61 let curIndex = 1;

Callers 1

getLineBreaksForStringFunction · 0.85

Calls 1

flushLineFunction · 0.85

Tested by

no test coverage detected