Skip to content

Commit

Permalink
Fix nav logic of overlapping 'first' ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
Discookie committed Feb 11, 2022
1 parent 4a40aea commit 1b79403
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/editor/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,21 @@ export class NavigationHandler {
}

if (cursor.isEqual(new Position(path.line-1, path.column-1))) {
// Set the first result if there's no exact-position match yet,
// or always set the last result
if ((which === 'first' && isExactPosition)) {
continue;
}

foundIdx = idx;
isExactPosition = true;

if (which === 'first') {
break;
}

continue;
}

// Check inside the ranges, but only if no exact match was found
if (!path.range || isExactPosition) {
// Set the first result if there's a range, there's nothing found yet,
// or set the last result if there's no exact-position match yet
if (!path.range || (which === 'first' && foundIdx !== null) || isExactPosition) {
continue;
}

Expand All @@ -128,10 +131,6 @@ export class NavigationHandler {

if (range.contains(cursor)) {
foundIdx = idx;

if (which === 'first') {
break;
}
}
}

Expand Down

0 comments on commit 1b79403

Please sign in to comment.