diff options
author | Lukas Tobler <lukas@tobler.dev> | 2020-12-27 17:34:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-27 17:34:41 +0100 |
commit | 7029a2a637355e6cee7611172f77be4648d1b2b2 (patch) | |
tree | 48c0186ff2859325d46bef611ec5b46856199d44 | |
parent | 20f4b9362bfcd06f0fe4d8b9f7ed1eb2a04d0f1b (diff) | |
parent | 8798f44e5933354106df1ee9e9cb644b5862bdb9 (diff) | |
download | vis-commentary-7029a2a637355e6cee7611172f77be4648d1b2b2.tar.gz |
Merge pull request #7 from bzbug/multiple-cursors
Add support for multiple cursors
-rw-r--r-- | vis-commentary.lua | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/vis-commentary.lua b/vis-commentary.lua index f8a2b4f..6ad5f52 100644 --- a/vis-commentary.lua +++ b/vis-commentary.lua @@ -104,24 +104,26 @@ end vis:map(vis.modes.NORMAL, "gcc", function() local win = vis.win local lines = win.file.lines - local lnum = win.selection.line - local col = win.selection.col local comment = comment_string[win.syntax] if not comment then return end local prefix, suffix = comment:match('^([^|]+)|?([^|]*)$') if not prefix then return end - toggle_line_comment(lines, lnum, prefix, suffix) + for sel in win:selections_iterator() do + local lnum = sel.line + local col = sel.col + + toggle_line_comment(lines, lnum, prefix, suffix) + sel:to(lnum, col) -- restore cursor position + end + win:draw() - win.selection:to(lnum, col) -- restore cursor position end, "Toggle comment on a the current line") local function visual_f(i) return function() local win = vis.win - local r = win.selection.range - local lnum = win.selection.line -- line number of cursor - local col = win.selection.col -- column of cursor + local lines = win.file.lines local comment = comment_string[win.syntax] if not comment then return end @@ -129,19 +131,25 @@ local function visual_f(i) local prefix, suffix = comment:match('^([^|]+)|?([^|]*)$') if not prefix then return end - if win.selection.anchored and r then - win.selection.pos = r.start - local a = win.selection.line - win.selection.pos = r.finish - local b = win.selection.line - i + for sel in win:selections_iterator() do + local r = sel.range + local lnum = sel.line -- line number of cursor + local col = sel.col -- column of cursor - local lines = win.file.lines - block_comment(lines, a, b, prefix, suffix) + if sel.anchored and r then + sel.pos = r.start + local a = sel.line + sel.pos = r.finish + local b = sel.line - i - win:draw() - win.selection:to(lnum, col) -- restore cursor position - vis.mode = vis.modes.NORMAL -- go to normal mode + block_comment(lines, a, b, prefix, suffix) + + sel:to(lnum, col) -- restore cursor position + end end + + win:draw() + vis.mode = vis.modes.NORMAL -- go to normal mode end end |