Skip to content

Commit 2e0572c

Browse files
committed
feat: make gco and gcO indent aware
1 parent 761f63f commit 2e0572c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lua/Comment/extra.lua

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ local function move_n_insert(row, col)
1414
A.nvim_feedkeys('a', 'ni', true)
1515
end
1616

17-
---@param count integer Line index
17+
---@param lnum integer Line index
1818
---@param ctype integer
1919
---@param cfg CommentConfig
20-
local function ins_on_line(count, ctype, cfg)
20+
local function ins_on_line(lnum, ctype, cfg)
2121
local row, col = unpack(A.nvim_win_get_cursor(0))
2222

2323
---@type CommentCtx
@@ -28,19 +28,18 @@ local function ins_on_line(count, ctype, cfg)
2828
range = { srow = row, scol = col, erow = row, ecol = col },
2929
}
3030

31-
local srow = row + count
31+
local srow = row + lnum
3232
local lcs, rcs = U.parse_cstr(cfg, ctx)
33-
local line = A.nvim_get_current_line()
34-
local indent = U.indent_len(line)
3533
local padding = U.get_pad(cfg.padding)
3634

3735
-- We need RHS of cstr, if we are doing block comments or if RHS exists
3836
-- because even in line comment RHS do exists for some filetypes like jsx_element, ocaml
3937
local if_rcs = U.is_empty(rcs) and rcs or padding .. rcs
4038

41-
A.nvim_buf_set_lines(0, srow, srow, false, { table.concat({ string.rep(' ', indent), lcs, padding, if_rcs }) })
42-
43-
move_n_insert(srow + 1, indent + #lcs + #padding - 1)
39+
A.nvim_buf_set_lines(0, srow, srow, false, { lcs .. padding .. if_rcs })
40+
A.nvim_win_set_cursor(0, { srow + 1, 0 })
41+
A.nvim_command('normal! ==')
42+
move_n_insert(srow + 1, #A.nvim_get_current_line() - #if_rcs - 1)
4443
U.is_fn(cfg.post_hook, ctx)
4544
end
4645

0 commit comments

Comments
 (0)