ruifm / gitlinker.nvim

A lua neovim plugin to generate shareable file permalinks (with line ranges) for several git web frontend hosts. Inspired by tpope/vim-fugitive's :GBrowse
GNU General Public License v3.0
525 stars 44 forks source link

line number order depends on visual mode cursor position #65

Closed alicewriteswrongs closed 1 year ago

alicewriteswrongs commented 2 years ago

Describe the bug

A clear and concise description of what the bug is:

When grabbing a permalink for a visually-selected range the ordering of the line numbers at the end of the URL is dependent on the cursor position in the visual selection (i.e. is it on the first line of the selection or the last line).

What were you trying to do?

Trying to get a github permalink URL for a visually-selected range of lines.

What was the expected result?

I expect the line numbers to be in ascending order, like L2-L23, rather than dependent on cursor state.

Note that the line number ordering doesn't matter when opening a link in the browser to view the selected lines, so if you're just looking to open the page in the browser then

https://github.com/alicewriteswrongs/dotfiles/blob/c61ec53b39c49202aff593387fcb483cb0f74fee/nvim/init.vim#L481-L483

is as good as

https://github.com/alicewriteswrongs/dotfiles/blob/c61ec53b39c49202aff593387fcb483cb0f74fee/nvim/init.vim#L483-L481

However, I was a bit sad to learn today that github is not so flexible if you are trying to reference code in a comment. Normally for permalinks in the same repo Github will expand a link into a little embed, like so:

https://github.com/ruifm/gitlinker.nvim/blob/c68d4873a14d2ae614875685ccca2e49472989e8/lua/gitlinker.lua#L3-L6

But this link, which just has the order of the line numbers swapped, doesn't work:

https://github.com/ruifm/gitlinker.nvim/blob/c68d4873a14d2ae614875685ccca2e49472989e8/lua/gitlinker.lua#L6-L3

What was the actual result?

If the cursor is on the first line of the selection then the order is swapped, so it's $ENDLINE-$STARTLINE, but if I have the cursor on the last line of the selection then it's $STARTLINE-$ENDLINE.

To Reproduce

I'm not using any fancy setup stuff, just doing the following in my init.vim:

require"gitlinker".setup()

To reproduce the error:

  1. open a file
  2. enter visual selection mode
  3. select a range of lines and do <leader>gy to get the git permalink
  4. observe that the order of the line numbers depends on whether the visual mode cursor is at the end or the beginning of the selection (see video below). I can freely toggle back-and-forth between these two behaviors by hitting o.

Screenshots

https://user-images.githubusercontent.com/6207644/192338802-c879b53f-ae45-4a77-a9d8-51a978cf3ea2.mov

System (please complete the following information):