Skip to content

Commit

Permalink
Fix issue with motion acting on last visual selection
Browse files Browse the repository at this point in the history
  • Loading branch information
terrortylor committed Feb 14, 2021
1 parent f8c6c6c commit 3f2389c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Changelog
======================

2021-02-12 - Fix issue with motion acting on last visual selection
9 changes: 4 additions & 5 deletions lua/nvim_comment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ local function uncomment_line(l, left, right)
return line
end

function M.operator()
local mode = api.nvim_call_function("visualmode", {})
local line1, line2
function M.operator(mode)
if not mode then
line1 = api.nvim_win_get_cursor(0)[1]
line2 = line1
Expand All @@ -99,7 +97,8 @@ function M.operator()
line1 = api.nvim_buf_get_mark(0, "[")[1]
line2 = api.nvim_buf_get_mark(0, "]")[1]
end
M.comment_toggle(line1, line2)

M.comment_toggle(line1, line2)
end

function M.comment_toggle(line_start, line_end)
Expand Down Expand Up @@ -158,7 +157,7 @@ function M.setup(user_opts)

-- Messy, change with nvim_exec once merged
vim.api.nvim_command('let g:loaded_text_objects_plugin = 1')
local vim_func = "function! CommentOperator(type) abort \n execute \"lua require('nvim_comment').operator()\" \n endfunction" -- luacheck:ignore
local vim_func = "function! CommentOperator(type) abort \n let reg_save = @@\n execute \"lua require('nvim_comment').operator('\" . a:type. \"')\"\n let @@ = reg_save\n endfunction"
vim.api.nvim_call_function("execute", {vim_func})
vim.api.nvim_command("command! -range CommentToggle lua require('nvim_comment').comment_toggle(<line1>, <line2>)")

Expand Down

0 comments on commit 3f2389c

Please sign in to comment.