chore: enforce brackets for if clause and for/while loops
This commit is contained in:
@@ -171,7 +171,9 @@ export class CharacterComparisonEngine {
|
||||
|
||||
for (let sIdx = start.segmentIndex; sIdx <= end.segmentIndex; sIdx++) {
|
||||
const segmentText = this.#preparedA!.segments[sIdx];
|
||||
if (segmentText === undefined) continue;
|
||||
if (segmentText === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// PERFORMANCE: Reuse segmenter results if possible, but for now just optimize the loop
|
||||
const graphemes = Array.from(this.#segmenter.segment(segmentText), s => s.segment);
|
||||
@@ -242,7 +244,9 @@ export class CharacterComparisonEngine {
|
||||
const line = this.#lastResult.lines[lineIndex];
|
||||
const char = line.chars[charIndex];
|
||||
|
||||
if (!char) return { proximity: 0, isPast: false };
|
||||
if (!char) {
|
||||
return { proximity: 0, isPast: false };
|
||||
}
|
||||
|
||||
// Center the comparison on the unified width
|
||||
// In the UI, lines are centered. So we need to calculate the global X.
|
||||
@@ -279,9 +283,15 @@ export class CharacterComparisonEngine {
|
||||
|
||||
unified.breakableFitAdvances = intA.breakableFitAdvances.map((advA: number[] | null, i: number) => {
|
||||
const advB = intB.breakableFitAdvances[i];
|
||||
if (!advA && !advB) return null;
|
||||
if (!advA) return advB;
|
||||
if (!advB) return advA;
|
||||
if (!advA && !advB) {
|
||||
return null;
|
||||
}
|
||||
if (!advA) {
|
||||
return advB;
|
||||
}
|
||||
if (!advB) {
|
||||
return advA;
|
||||
}
|
||||
|
||||
return advA.map((w: number, j: number) => Math.max(w, advB[j]));
|
||||
});
|
||||
|
||||
@@ -127,7 +127,9 @@ export class TextLayoutEngine {
|
||||
// Both cursors are grapheme-level: start is inclusive, end is exclusive.
|
||||
for (let sIdx = start.segmentIndex; sIdx <= end.segmentIndex; sIdx++) {
|
||||
const segmentText = prepared.segments[sIdx];
|
||||
if (segmentText === undefined) continue;
|
||||
if (segmentText === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const graphemes = Array.from(this.#segmenter.segment(segmentText), s => s.segment);
|
||||
const advances = breakableFitAdvances[sIdx];
|
||||
|
||||
@@ -150,7 +150,9 @@ export function createResponsiveManager(customBreakpoints?: Partial<Breakpoints>
|
||||
* @returns Cleanup function to remove listeners
|
||||
*/
|
||||
function init() {
|
||||
if (typeof window === 'undefined') return;
|
||||
if (typeof window === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
const handleResize = () => {
|
||||
width = window.innerWidth;
|
||||
|
||||
@@ -175,7 +175,9 @@ export function createVirtualizer<T>(
|
||||
const { count, data } = options;
|
||||
// Implicit dependency
|
||||
const v = _version;
|
||||
if (count === 0 || containerHeight === 0 || !data) return [];
|
||||
if (count === 0 || containerHeight === 0 || !data) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const overscan = options.overscan ?? 5;
|
||||
|
||||
@@ -264,7 +266,9 @@ export function createVirtualizer<T>(
|
||||
containerHeight = window.innerHeight;
|
||||
|
||||
const handleScroll = () => {
|
||||
if (rafId !== null) return;
|
||||
if (rafId !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
rafId = requestAnimationFrame(() => {
|
||||
// Get current position of element relative to viewport
|
||||
@@ -323,7 +327,9 @@ export function createVirtualizer<T>(
|
||||
};
|
||||
|
||||
const resizeObserver = new ResizeObserver(([entry]) => {
|
||||
if (entry) containerHeight = entry.contentRect.height;
|
||||
if (entry) {
|
||||
containerHeight = entry.contentRect.height;
|
||||
}
|
||||
});
|
||||
|
||||
node.addEventListener('scroll', handleScroll, { passive: true });
|
||||
@@ -423,7 +429,9 @@ export function createVirtualizer<T>(
|
||||
* ```
|
||||
*/
|
||||
function scrollToIndex(index: number, align: 'start' | 'center' | 'end' | 'auto' = 'auto') {
|
||||
if (!elementRef || index < 0 || index >= options.count) return;
|
||||
if (!elementRef || index < 0 || index >= options.count) {
|
||||
return;
|
||||
}
|
||||
|
||||
const itemStart = offsets[index];
|
||||
const itemSize = measuredSizes[index] ?? options.estimateSize(index);
|
||||
@@ -431,16 +439,24 @@ export function createVirtualizer<T>(
|
||||
const { useWindowScroll } = optionsGetter();
|
||||
|
||||
if (useWindowScroll) {
|
||||
if (align === 'center') target = itemStart - window.innerHeight / 2 + itemSize / 2;
|
||||
if (align === 'end') target = itemStart - window.innerHeight + itemSize;
|
||||
if (align === 'center') {
|
||||
target = itemStart - window.innerHeight / 2 + itemSize / 2;
|
||||
}
|
||||
if (align === 'end') {
|
||||
target = itemStart - window.innerHeight + itemSize;
|
||||
}
|
||||
|
||||
// Add container offset to target to get absolute document position
|
||||
const absoluteTarget = target + elementOffsetTop;
|
||||
|
||||
window.scrollTo({ top: absoluteTarget, behavior: 'smooth' });
|
||||
} else {
|
||||
if (align === 'center') target = itemStart - containerHeight / 2 + itemSize / 2;
|
||||
if (align === 'end') target = itemStart - containerHeight + itemSize;
|
||||
if (align === 'center') {
|
||||
target = itemStart - containerHeight / 2 + itemSize / 2;
|
||||
}
|
||||
if (align === 'end') {
|
||||
target = itemStart - containerHeight + itemSize;
|
||||
}
|
||||
|
||||
elementRef.scrollTo({ top: target, behavior: 'smooth' });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user