Skip to content

Commit

Permalink
Fix getVisualSelection() when called from visual mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jerome-pouiller committed Nov 2, 2022
1 parent 735e929 commit e8f7163
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions plugin/Highlight.vim
Expand Up @@ -1199,8 +1199,17 @@ function s:getVisualSelection()
" https://stackoverflow.com/questions/1533565/how-to-get-visually-selected-text-in-vimscript
"
" Why is this not a built-in Vim script function?!
let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
if mode() == "v"
let [line_start, column_start] = getpos("v")[1:2]
let [line_end, column_end] = getpos(".")[1:2]
else
let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
end
if (line2byte(line_start) + column_start) > (line2byte(line_end) + column_end)
let [line_start, column_start, line_end, column_end] =
\ [line_end, column_end, line_start, column_start]
end
let lines = getline(line_start, line_end)
if len(lines) == 0
return ''
Expand Down

0 comments on commit e8f7163

Please sign in to comment.