Skip to content

Commit 8b59b30

Browse files
committed
rename Inline/Run start, end to textStart, textEnd
Box will soon have treeStart and treeFinal, so just `start` and `end` on the inline would be confusing
1 parent 19d5559 commit 8b59b30

4 files changed

Lines changed: 46 additions & 46 deletions

File tree

src/layout-flow.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,13 +1091,13 @@ export class Inline extends Box {
10911091
public children: InlineLevel[];
10921092
public nshaped: number;
10931093
public metrics: InlineMetrics;
1094-
public start: number;
1095-
public end: number;
1094+
public textStart: number;
1095+
public textEnd: number;
10961096

10971097
constructor(start: number, end: number, style: Style, children: InlineLevel[], attrs: number) {
10981098
super(style, attrs);
1099-
this.start = start;
1100-
this.end = end;
1099+
this.textStart = start;
1100+
this.textEnd = end;
11011101
this.children = children;
11021102
this.nshaped = 0;
11031103
this.metrics = EmptyInlineMetrics;
@@ -1275,12 +1275,12 @@ export class IfcInline extends Inline {
12751275
if ('sentinel' in box) {
12761276
while (
12771277
itemIndex < this.paragraph.items.length &&
1278-
this.paragraph.items[itemIndex].offset < box.sentinel.end
1278+
this.paragraph.items[itemIndex].offset < box.sentinel.textEnd
12791279
) {
12801280
const item = this.paragraph.items[itemIndex];
12811281
item.x += containingBlock.x;
12821282
item.y += containingBlock.y;
1283-
if (item.end() > box.sentinel.start) {
1283+
if (item.end() > box.sentinel.textStart) {
12841284
item.x += dx;
12851285
item.y += dy;
12861286
}

src/layout-text.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,21 @@ export function prevGrapheme(text: string, index: number) {
7272
}
7373

7474
export class Run extends RenderItem {
75-
public start: number;
76-
public end: number;
75+
public textStart: number;
76+
public textEnd: number;
7777

7878
static TEXT_BITS = Box.BITS.hasText
7979
| Box.BITS.hasForegroundInLayer
8080
| Box.BITS.hasForegroundInDescendent;
8181

8282
constructor(start: number, end: number, style: Style) {
8383
super(style);
84-
this.start = start;
85-
this.end = end;
84+
this.textStart = start;
85+
this.textEnd = end;
8686
}
8787

8888
get length() {
89-
return this.end - this.start;
89+
return this.textEnd - this.textStart;
9090
}
9191

9292
getLogSymbol() {
@@ -113,9 +113,9 @@ export class Run extends RenderItem {
113113
}
114114

115115
logName(log: Logger, options?: RenderItemLogOptions) {
116-
log.text(`${this.start},${this.end}`);
116+
log.text(`${this.textStart},${this.textEnd}`);
117117
if (options?.paragraphText) {
118-
log.text(` "${loggableText(options.paragraphText.slice(this.start, this.end))}"`);
118+
log.text(` "${loggableText(options.paragraphText.slice(this.textStart, this.textEnd))}"`);
119119
}
120120
}
121121

@@ -126,7 +126,7 @@ export class Run extends RenderItem {
126126
parent.bitfield |= Run.TEXT_BITS;
127127
}
128128

129-
for (let i = this.start; i < this.end; i++) {
129+
for (let i = this.textStart; i < this.textEnd; i++) {
130130
const code = paragraph.charCodeAt(i);
131131

132132
if (code & NON_ASCII_MASK) {
@@ -167,21 +167,21 @@ export function collapseWhitespace(ifc: IfcInline) {
167167

168168
if ('post' in item) {
169169
const inline = item.post;
170-
inline.end -= delta;
170+
inline.textEnd -= delta;
171171
parents.pop();
172172
} else if (item.isInline()) {
173-
item.start -= delta;
173+
item.textStart -= delta;
174174
parents.push(item);
175175
stack.push({post: item});
176176
for (let i = item.children.length - 1; i >= 0; --i) stack.push(item.children[i]);
177177
} else if (item.isRun()) {
178178
const whiteSpace = item.style.whiteSpace;
179-
const originalStart = item.start;
179+
const originalStart = item.textStart;
180180

181-
item.start -= delta;
181+
item.textStart -= delta;
182182

183183
if (whiteSpace === 'normal' || whiteSpace === 'nowrap') {
184-
for (let i = originalStart; i < item.end; i++) {
184+
for (let i = originalStart; i < item.textEnd; i++) {
185185
const isWhitespace = isSpaceOrTabOrNewline(ifc.text[i]);
186186

187187
if (inWhitespace && isWhitespace) {
@@ -193,14 +193,14 @@ export function collapseWhitespace(ifc: IfcInline) {
193193
inWhitespace = isWhitespace;
194194
}
195195
} else if (whiteSpace === 'pre-line') {
196-
for (let i = originalStart; i < item.end; i++) {
196+
for (let i = originalStart; i < item.textEnd; i++) {
197197
const isWhitespace = isSpaceOrTabOrNewline(ifc.text[i]);
198198

199199
if (isWhitespace) {
200200
let j = i + 1;
201201
let hasNewline = isNewline(ifc.text[i]);
202202

203-
for (; j < item.end && isSpaceOrTabOrNewline(ifc.text[j]); j++) {
203+
for (; j < item.textEnd && isSpaceOrTabOrNewline(ifc.text[j]); j++) {
204204
hasNewline = hasNewline || isNewline(ifc.text[j]);
205205
}
206206

@@ -228,12 +228,12 @@ export function collapseWhitespace(ifc: IfcInline) {
228228
}
229229
} else { // pre
230230
inWhitespace = false;
231-
for (let i = originalStart; i < item.end; i++) {
231+
for (let i = originalStart; i < item.textEnd; i++) {
232232
str[stri++] = ifc.text.charCodeAt(i);
233233
}
234234
}
235235

236-
item.end -= delta;
236+
item.textEnd -= delta;
237237

238238
if (item.length === 0) {
239239
const parent = parents.at(-1)!;
@@ -247,7 +247,7 @@ export function collapseWhitespace(ifc: IfcInline) {
247247
}
248248

249249
ifc.text = decoder.decode(str.subarray(0, stri));
250-
ifc.end = ifc.text.length;
250+
ifc.textEnd = ifc.text.length;
251251
}
252252

253253
export interface ShapingAttrs {
@@ -603,10 +603,10 @@ export class ShapedItem implements IfcRenderItem {
603603
this.glyphs = leftGlyphs;
604604
this.length = offset;
605605
this.inlines = inlines.filter(inline => {
606-
return inline.start < this.end() && inline.end > this.offset;
606+
return inline.textStart < this.end() && inline.textEnd > this.offset;
607607
});
608608
right.inlines = inlines.filter(inline => {
609-
return inline.start < right.end() && inline.end > right.offset;
609+
return inline.textStart < right.end() && inline.textEnd > right.offset;
610610
});
611611

612612
for (const i of right.inlines) i.nshaped += 1;
@@ -2229,7 +2229,7 @@ export class Paragraph {
22292229

22302230
if (mark.inlinePre) {
22312231
candidates.height.pushInline(mark.inlinePre);
2232-
if (item && item.offset <= mark.inlinePre.start && item.end() > mark.inlinePre.start) {
2232+
if (item && item.offset <= mark.inlinePre.textStart && item.end() > mark.inlinePre.textStart) {
22332233
candidates.height.stampMetrics(getMetrics(mark.inlinePre.style, item.face));
22342234
}
22352235
parents.push(mark.inlinePre);
@@ -2574,7 +2574,7 @@ export class Paragraph {
25742574
const count = counts.get(inline);
25752575
const isFirstOccurance = count === undefined;
25762576
const isOrthogonal = (item.attrs.level & 1 ? 'rtl' : 'ltr') !== direction;
2577-
const mark = isOrthogonal ? inline.end : inline.start;
2577+
const mark = isOrthogonal ? inline.textEnd : inline.textStart;
25782578
const alignmentContext = linebox.contextRoots.get(inline);
25792579

25802580
bgcursor = x;
@@ -2635,7 +2635,7 @@ export class Paragraph {
26352635
const count = counts.get(inline)!;
26362636
const isLastOccurance = count === inline.nshaped;
26372637
const isOrthogonal = (item.attrs.level & 1 ? 'rtl' : 'ltr') !== direction;
2638-
const mark = isOrthogonal ? inline.start : inline.end;
2638+
const mark = isOrthogonal ? inline.textStart : inline.textEnd;
26392639

26402640
bgcursor = x;
26412641

src/paint.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ function drawText(
105105
tx += axToStart * toPx;
106106

107107
// TODO: should really have isStartColorBoundary, isEndColorBoundary
108-
const isColorBoundary = textStart !== item.offset && textStart === run.start
109-
|| textEnd !== item.end() && textEnd === run.end;
108+
const isColorBoundary = textStart !== item.offset && textStart === run.textStart
109+
|| textEnd !== item.end() && textEnd === run.textEnd;
110110

111111
b.fillColor = run.style.color;
112112
b.fontSize = style.fontSize;
@@ -322,19 +322,19 @@ function paintInline(
322322
const fragments: InlineFragment[] = [];
323323
let fragmentIndex = 0;
324324
const stack: InlineLevel[] = [inlineRoot];
325-
let lastMark = inlineRoot.start;
326-
let inlineMark = inlineRoot.start;
325+
let lastMark = inlineRoot.textStart;
326+
let inlineMark = inlineRoot.textStart;
327327
let run: Run | undefined = undefined;
328-
let mark = inlineRoot.start;
328+
let mark = inlineRoot.textStart;
329329
let itemIndex = 0; // common case, adjusted below if necessary
330330
let itemEnd = items.length; // common case, adjusted below
331331

332-
if (items.length > 0 && inlineRoot.start !== items[0].offset) {
333-
itemIndex = binarySearchOf(items, inlineRoot.start, item => item.end());
334-
if (items[itemIndex].end() === inlineRoot.start) itemIndex += 1;
332+
if (items.length > 0 && inlineRoot.textStart !== items[0].offset) {
333+
itemIndex = binarySearchOf(items, inlineRoot.textStart, item => item.end());
334+
if (items[itemIndex].end() === inlineRoot.textStart) itemIndex += 1;
335335
}
336-
if (items.length > 0 && inlineRoot.end !== items[itemEnd - 1].end()) {
337-
itemEnd = binarySearchOf(items, inlineRoot.end, item => item.end()) + 1;
336+
if (items.length > 0 && inlineRoot.textEnd !== items[itemEnd - 1].end()) {
337+
itemEnd = binarySearchOf(items, inlineRoot.textEnd, item => item.end()) + 1;
338338
}
339339

340340
while (
@@ -374,7 +374,7 @@ function paintInline(
374374
} else {
375375
while (
376376
itemIndex < itemEnd &&
377-
items[itemIndex].end() <= box.end
377+
items[itemIndex].end() <= box.textEnd
378378
) itemIndex++;
379379
}
380380
} else if (box.isFormattingBox()) {
@@ -388,7 +388,7 @@ function paintInline(
388388
}
389389
} else if (box.isRun()) {
390390
run = box;
391-
inlineMark = box.end;
391+
inlineMark = box.textEnd;
392392
}
393393
}
394394

@@ -397,7 +397,7 @@ function paintInline(
397397
fragmentIndex < fragments.length ? fragments[fragmentIndex].textOffset : Infinity,
398398
itemIndex < itemEnd ? items[itemIndex].end() : Infinity,
399399
inlineMark,
400-
inlineRoot.end
400+
inlineRoot.textEnd
401401
);
402402
}
403403
}

test/text.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,11 +649,11 @@ describe('Lines', function () {
649649
const [ifc] = this.get('div').children;
650650
expect(ifc.paragraph.items).to.have.lengthOf(2);
651651
expect(ifc.paragraph.items[0].inlines).to.have.lengthOf(2);
652-
expect(ifc.paragraph.items[0].inlines[0].end).to.equal(19);
653-
expect(ifc.paragraph.items[0].inlines[1].end).to.equal(10);
652+
expect(ifc.paragraph.items[0].inlines[0].textEnd).to.equal(19);
653+
expect(ifc.paragraph.items[0].inlines[1].textEnd).to.equal(10);
654654
expect(ifc.paragraph.items[1].inlines).to.have.lengthOf(2);
655-
expect(ifc.paragraph.items[1].inlines[0].end).to.equal(19);
656-
expect(ifc.paragraph.items[1].inlines[1].end).to.equal(19);
655+
expect(ifc.paragraph.items[1].inlines[0].textEnd).to.equal(19);
656+
expect(ifc.paragraph.items[1].inlines[1].textEnd).to.equal(19);
657657
});
658658

659659
it('considers padding-right on a break as belonging to the left word', function () {

0 commit comments

Comments
 (0)