From f7801fe138d9677c9333650b4d5581489d4b0613 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 31 Jan 2022 15:44:54 +0800 Subject: [PATCH] vim-patch:8.2.3935: CTRL-U in Insert mode does not fix the indent Problem: CTRL-U in Insert mode does not fix the indent. Solution: Fix the indent when 'cindent' is set. https://github.com/vim/vim/commit/5d20fbf2e79b96a39abbdadc486b656cdcc67ed6 --- src/nvim/edit.c | 8 ++++++++ src/nvim/testdir/test_textformat.vim | 17 ++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 3d2cfa5c2a..f96e7261ca 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -8299,6 +8299,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) int in_indent; int oldState; int cpc[MAX_MCO]; // composing characters + bool call_fix_indent = false; // can't delete anything in an empty file // can't backup past first character in buffer @@ -8442,6 +8443,8 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) beginline(BL_WHITE); if (curwin->w_cursor.col < save_col) { mincol = curwin->w_cursor.col; + // should now fix the indent to match with the previous line + call_fix_indent = true; } curwin->w_cursor.col = save_col; } @@ -8576,6 +8579,11 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) if (curwin->w_cursor.col <= 1) { did_ai = false; } + + if (call_fix_indent) { + fix_indent(); + } + // It's a little strange to put backspaces into the redo // buffer, but it makes auto-indent a lot easier to deal // with. diff --git a/src/nvim/testdir/test_textformat.vim b/src/nvim/testdir/test_textformat.vim index 5cebdef7f1..e1d155eba7 100644 --- a/src/nvim/testdir/test_textformat.vim +++ b/src/nvim/testdir/test_textformat.vim @@ -238,7 +238,7 @@ func Test_format_c_comment() END call assert_equal(expected, getline(1, '$')) - " Using "o" repeates the line comment, "O" does not. + " Using "o" repeats the line comment, "O" does not. %del let text =<< trim END nop; @@ -261,6 +261,21 @@ func Test_format_c_comment() END call assert_equal(expected, getline(1, '$')) + " Using CTRL-U after "o" fixes the indent + %del + let text =<< trim END + { + val = val; // This is a comment + END + call setline(1, text) + exe "normal! 2Go\x\" + let expected =<< trim END + { + val = val; // This is a comment + x + END + call assert_equal(expected, getline(1, '$')) + bwipe! endfunc