diff --git a/src/text-buf.ts b/src/text-buf.ts index 3d0955e..7d9fa2a 100644 --- a/src/text-buf.ts +++ b/src/text-buf.ts @@ -406,17 +406,17 @@ export class TextBuf { while (!x.nil) { if (index < x.left.total_len) { x = x.left; - } else { - index -= x.left.total_len; + continue; + } - if (index < x.slice_len) { - return { node: x, offset: index }; - } else { - index -= x.slice_len; + index -= x.left.total_len; - x = x.right; - } + if (index < x.slice_len) { + return { node: x, offset: index }; } + + index -= x.slice_len; + x = x.right; } }