toggle comment depends on previous line

like Ctrl+/ in pycharm, vscode and so on
This commit is contained in:
Maksim Nikulin
2023-11-26 22:31:49 +03:00
parent da948e160d
commit 8608a214d1
2 changed files with 6 additions and 5 deletions

View File

@@ -1019,7 +1019,8 @@ function! s:CommentLinesToggle(forceNested, firstLine, lastLine) abort
let currentLine = a:firstLine
let align = g:NERDDefaultAlign
let leftAlignIndx = align ==# 'start' ? 0 : s:LeftMostIndx(a:forceNested, 0, a:firstLine, a:lastLine)
let lookBehind = align ==# 'previous' && currentLine != 1 && s:IsCommentedFromStartOfLine(s:Left(), getline(currentLine - 1))
let leftAlignIndx = align ==# 'start' ? 0 : s:LeftMostIndx(a:forceNested, 0, a:firstLine - lookBehind, a:lastLine)
let rightAlignIndx = s:RightMostIndx(a:forceNested, 0, a:firstLine, a:lastLine)
let rightAlignIndx = rightAlignIndx + strlen(s:Left({'space': 1}))
@@ -1037,7 +1038,7 @@ function! s:CommentLinesToggle(forceNested, firstLine, lastLine) abort
let theLine = s:SwapOuterMultiPartDelimsForPlaceHolders(theLine)
endif
if align ==# 'left' || align ==# 'start' || align ==# 'both'
if align ==# 'left' || align ==# 'start' || align ==# 'both' || align ==# 'previous'
let theLine = s:AddLeftDelimAligned(s:Left({'space': 1}), theLine, leftAlignIndx)
else
let theLine = s:AddLeftDelim(s:Left({'space': 1}), theLine)