Skip to content

Commit

Permalink
fix: visual lines (#57)
Browse files Browse the repository at this point in the history
* fix: visual lines

* fix: visual lines
  • Loading branch information
linrongbin16 committed Jul 15, 2023
1 parent 1a8c597 commit b50ca53
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lua/gitlinker/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,34 @@ local function relative_path(cwd)
return relpath
end

local function is_visual_mode(m)
return type(m) == "string" and m:upper() == "V"
or m:upper() == "CTRL-V"
or m:upper() == "<C-V>"
or m == "\22"
end

--- @class LineRange
--- @field lstart integer
--- @field lend integer

--- @return LineRange
local function line_range()
local pos1 = vim.fn.getpos("v")[2]
local pos2 = vim.fn.getcurpos()[2]
vim.cmd([[execute "normal! \<ESC>"]])
local mode = vim.fn.visualmode()
local pos1 = nil
local pos2 = nil
if is_visual_mode(mode) then
pos1 = vim.fn.getpos("'<")[2]
pos2 = vim.fn.getpos("'>")[2]
else
pos1 = vim.fn.getpos("v")[2]
-- if mode == "v" then
-- pos2 = vim.fn.getpos(".")[2]
-- else
pos2 = vim.fn.getcurpos()[2]
-- end
end
local lstart = math.min(pos1, pos2)
local lend = math.max(pos1, pos2)
return { lstart = lstart, lend = lend }
Expand Down

0 comments on commit b50ca53

Please sign in to comment.