Skip to content

Commit

Permalink
Merge pull request #75 from Discookie/ericsson/fix-kb-navigation
Browse files Browse the repository at this point in the history
Fix keyboard navigation commands
  • Loading branch information
csordasmarton authored Feb 14, 2022
2 parents ce38fa6 + 1b79403 commit 468e442
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/editor/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,42 +93,44 @@ export class NavigationHandler {
const entry = ExtensionApi.diagnostics.selectedEntry.diagnostic;
const reprPath = entry.bug_path_events;

// The cursor is on the bug's original jump location
let isExactPosition = false;
let foundIdx = null;

for (const [idx, path] of reprPath.entries()) {
// Check location first
if (window.activeTextEditor.document.uri.fsPath !== entry.file.original_path) {
if (window.activeTextEditor.document.uri.fsPath !== path.file.original_path) {
continue;
}

if (cursor.isEqual(new Position(path.line-1, path.column-1))) {
foundIdx = idx;

if (which === 'first') {
break;
// 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;

continue;
}

// Check inside the ranges
if (!path.range) {
// 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;
}

const range = new Range(
path.range.start_line-1,
path.range.start_col-1,
path.range.start_line-1,
path.range.start_col,
path.range.end_line-1,
path.range.end_col,
);

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

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

Expand All @@ -148,7 +150,7 @@ export class NavigationHandler {
if (stepIdx < reprPath.length - 1) {
const step = reprPath[stepIdx + 1];

window.showTextDocument(Uri.file(entry.file.original_path), {
window.showTextDocument(Uri.file(step.file.original_path), {
selection: new Range(
step.line - 1,
step.column - 1,
Expand All @@ -172,7 +174,7 @@ export class NavigationHandler {
if (stepIdx > 0) {
const step = reprPath[stepIdx - 1];

window.showTextDocument(Uri.file(entry.file.original_path), {
window.showTextDocument(Uri.file(step.file.original_path), {
selection: new Range(
step.line - 1,
step.column - 1,
Expand Down

0 comments on commit 468e442

Please sign in to comment.