Skip to content

Support negative line numbers for goto#841

Open
barkure wants to merge 2 commits intomicrosoft:mainfrom
barkure:support-negative-line-goto
Open

Support negative line numbers for goto#841
barkure wants to merge 2 commits intomicrosoft:mainfrom
barkure:support-negative-line-goto

Conversation

@barkure
Copy link
Copy Markdown
Contributor

@barkure barkure commented May 1, 2026

Summary

Implements the request from #684.

  • Support negative line numbers for file goto targets, e.g. edit README.md:-1 opens at the last line and edit README.md:-5 opens at the fifth line from the end.
  • Apply the same negative line behavior to the interactive Go To dialog, so CLI and in-editor navigation stay consistent.
  • Keep columns positive-only; values like README.md:10:-5 are not treated as goto targets.

Test plan

  • Built successfully with:
cargo build -p edit --release
  • Ran parser coverage with:
cargo test -p edit documents::tests::test_parse_last_numbers
  • Manually tested:
    target/release/edit README.md:-1
    target/release/edit README.md:-5

Comment thread crates/edit/src/bin/edit/documents.rs Outdated
Comment on lines +39 to +47
pub fn resolve(self, line_count: CoordType) -> Point {
let line = if self.line < 0 {
line_count.saturating_add(self.line)
} else {
self.line.saturating_sub(1)
};

Point { x: self.column, y: line.max(0) }
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me it seems unnecessary to introduce a new type just to wrap a single if condition in a function. It should be fine to keep using Point and just move the if/else into the code below.

John Carmack wrote many years ago "If a function is only called from a single place, consider inlining it." It is as true as it has ever been.

@barkure
Copy link
Copy Markdown
Contributor Author

barkure commented May 4, 2026

Updated as suggested — removed GotoTarget and kept using Point, with the line resolution inlined at the call sites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants