lookbehind before context, so page increment is _upto_ context rows
[perl/list-index.git] / lib / List / Index.pm
index 5b46313d7272168dea172ddf5135ce9ef480dae0..4a2118910cf3708c11ada4bc07644930a33f3486 100644 (file)
@@ -28,9 +28,9 @@ sub ranges {
        while ($offset < @$self) {
                my $link = substr $self->[$offset], 0, $length;
                if ($context) {
-                       {
+                       if ($offset > $context - 1) {
                                # take a value slightly before the current offset
-                               my $before = $offset > $context ? $self->[$offset - $context] : '.';
+                               my $before = $self->[$offset - $context - 1];
                                # see how much of it matches the current link
                                my $trim = 1;
                                for my $match (split //, $before) {