aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-05-08 07:51:12 +0800
committerGitHub <noreply@github.com>2022-05-08 07:51:12 +0800
commit1b1cc4d864b4b15e705c1a500e64c7bfbacedae7 (patch)
tree06aace613926c87635dcc9e9baf1d43fede17202
parent0a00792332add35c23b7cf96618ea317e7383a11 (diff)
downloadrneovim-1b1cc4d864b4b15e705c1a500e64c7bfbacedae7.tar.gz
rneovim-1b1cc4d864b4b15e705c1a500e64c7bfbacedae7.tar.bz2
rneovim-1b1cc4d864b4b15e705c1a500e64c7bfbacedae7.zip
vim-patch:8.2.4908: no text formatting for // comment after a statement (#18472)
Problem: No text formatting for // comment after a statement. Solution: format a comment when the 'c' flag is in 'formatoptions'. https://github.com/vim/vim/commit/48a8a833033e10fc1eba96f2fc8dd19c2408eddf
-rw-r--r--src/nvim/edit.c13
-rw-r--r--src/nvim/testdir/test_textformat.vim12
2 files changed, 24 insertions, 1 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 3821cd3f41..e7c9eea27b 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -6033,7 +6033,18 @@ static void internal_format(int textwidth, int second_indent, int flags, int for
// Don't break until after the comment leader
if (do_comments) {
- leader_len = get_leader_len(get_cursor_line_ptr(), NULL, false, true);
+ char_u *line = get_cursor_line_ptr();
+ leader_len = get_leader_len(line, NULL, false, true);
+ if (leader_len == 0 && curbuf->b_p_cin) {
+ // Check for a line comment after code.
+ int comment_start = check_linecomment(line);
+ if (comment_start != MAXCOL) {
+ leader_len = get_leader_len(line + comment_start, NULL, false, true);
+ if (leader_len != 0) {
+ leader_len += comment_start;
+ }
+ }
+ }
} else {
leader_len = 0;
}
diff --git a/src/nvim/testdir/test_textformat.vim b/src/nvim/testdir/test_textformat.vim
index 714539d418..92705cb69f 100644
--- a/src/nvim/testdir/test_textformat.vim
+++ b/src/nvim/testdir/test_textformat.vim
@@ -342,6 +342,18 @@ func Test_format_c_comment()
END
call assert_equal(expected, getline(1, '$'))
+ " typing comment text auto-wraps
+ %del
+ call setline(1, text)
+ exe "normal! 2GA blah more text blah.\<Esc>"
+ let expected =<< trim END
+ {
+ val = val; // This is a comment
+ // blah more text
+ // blah.
+ END
+ call assert_equal(expected, getline(1, '$'))
+
bwipe!
endfunc