]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1145: multi-line completion has wrong indentation for last line v9.1.1145
authorglepnir <glephunter@gmail.com>
Mon, 24 Feb 2025 18:10:37 +0000 (19:10 +0100)
committerChristian Brabandt <cb@256bit.org>
Mon, 24 Feb 2025 18:10:37 +0000 (19:10 +0100)
Problem:  When expanding omni completion items with newlines (e.g.
          `then\n\t\nend`), the end statement gets wrong indentation.
Solution: Add OPENLINE_FORCE_INDENT flag to make open_line() use
          second_line_indent directly (glepnir)

closes: #16614

Signed-off-by: glepnir <glephunter@gmail.com>
Signed-off-by: Justin M. Keyes <justinkz@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/change.c
src/insexpand.c
src/testdir/dumps/Test_pum_with_special_characters_09.dump [new file with mode: 0644]
src/testdir/dumps/Test_pum_with_special_characters_10.dump [new file with mode: 0644]
src/testdir/dumps/Test_pum_with_special_characters_11.dump [new file with mode: 0644]
src/testdir/dumps/Test_pum_with_special_characters_12.dump [new file with mode: 0644]
src/testdir/test_popup.vim
src/version.c
src/vim.h

index 294adf7dfcccccfd6de26495377ee1386f152c8b..a3329bdcb9a4bbd5bf2ab23df5a15c4b6f9f52d2 100644 (file)
@@ -1385,6 +1385,8 @@ del_bytes(
  *         OPENLINE_KEEPTRAIL  keep trailing spaces
  *         OPENLINE_MARKFIX    adjust mark positions after the line break
  *         OPENLINE_COM_LIST   format comments with list or 2nd line indent
+ *         OPENLINE_FORCE_INDENT  set indent from second_line_indent, ignore
+ *                                'autoindent'
  *
  * "second_line_indent": indent for after ^^D in Insert mode or if flag
  *                       OPENLINE_COM_LIST
@@ -1498,9 +1500,11 @@ open_line(
     if (dir == FORWARD && did_ai)
        trunc_line = TRUE;
 
+    if ((flags & OPENLINE_FORCE_INDENT) && second_line_indent >= 0)
+       newindent = second_line_indent;
     // If 'autoindent' and/or 'smartindent' is set, try to figure out what
     // indent to use for the new line.
-    if (curbuf->b_p_ai || do_si)
+    else if (curbuf->b_p_ai || do_si)
     {
        // count white space on current line
 #ifdef FEAT_VARTABS
index deae1ce346588d65d4cb95c157e627f1439b420a..edc4265e438cbef6a3aa836d07e08ca04b93b834 100644 (file)
@@ -4473,6 +4473,7 @@ ins_compl_expand_multiple(char_u *str)
 {
     char_u     *start = str;
     char_u     *curr = str;
+    int                base_indent = get_indent();
 
     while (*curr != NUL)
     {
@@ -4483,7 +4484,7 @@ ins_compl_expand_multiple(char_u *str)
                ins_char_bytes(start, (int)(curr - start));
 
            // Handle newline
-           open_line(FORWARD, OPENLINE_KEEPTRAIL, FALSE, NULL);
+           open_line(FORWARD, OPENLINE_KEEPTRAIL | OPENLINE_FORCE_INDENT, base_indent, NULL);
            start = curr + 1;
        }
        curr++;
diff --git a/src/testdir/dumps/Test_pum_with_special_characters_09.dump b/src/testdir/dumps/Test_pum_with_special_characters_09.dump
new file mode 100644 (file)
index 0000000..7a6cac7
--- /dev/null
@@ -0,0 +1,12 @@
+|l+0&#ffffff0|o|c|a|l| |a| |=| |f+0#ff404010&|u|n|c| |(|)| +0#0000000&@57
+| +0#ff404010&@1| +0#0000000&@72
+|e+0#ff404010&|n|d> +0#0000000&@71
+|~+0#4040ff13&| | +0#0000001#e0e0e08|f|u|n|c|t|i|o|n| |(|)| @3| +0#4040ff13#ffffff0@56
+|~| | +0#0000001#ffd7ff255|f|o@1|b|a|r| @8| +0#4040ff13#ffffff0@56
+|~| | +0#0000001#ffd7ff255|你*&|好|^+&|@| @1|^|@|我*&|好| +&| +0#4040ff13#ffffff0@56
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |O|m|n|i| |c|o|m|p|l|e|t|i|o|n| |(|^|O|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |3| +0#0000000&@34
diff --git a/src/testdir/dumps/Test_pum_with_special_characters_10.dump b/src/testdir/dumps/Test_pum_with_special_characters_10.dump
new file mode 100644 (file)
index 0000000..ccaea76
--- /dev/null
@@ -0,0 +1,12 @@
+|l+0&#ffffff0|o|c|a|l| |a| |=| |f|u|n|c| |(|)| @57
+@75
+|e|n|d> @71
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|4| @10|A|l@1| 
diff --git a/src/testdir/dumps/Test_pum_with_special_characters_11.dump b/src/testdir/dumps/Test_pum_with_special_characters_11.dump
new file mode 100644 (file)
index 0000000..f6d8387
--- /dev/null
@@ -0,0 +1,12 @@
+|l+0&#ffffff0|o|c|a|l| |a| |=| |f|u|n|c| |(|)| @57
+@2|l|o|c|a|l| |b| |=| |f+0#ff404010&|u|n|c| |(|)| +0#0000000&@55
+| +0#ff404010&@3| +0#0000000&@70
+| +0#ff404010&@1|e|n|d> +0#0000000&@69
+|e|n|d| | +0#0000001#e0e0e08|f|u|n|c|t|i|o|n| |(|)| @3| +0#0000000#ffffff0@54
+|~+0#4040ff13&| @2| +0#0000001#ffd7ff255|f|o@1|b|a|r| @8| +0#4040ff13#ffffff0@54
+|~| @2| +0#0000001#ffd7ff255|你*&|好|^+&|@| @1|^|@|我*&|好| +&| +0#4040ff13#ffffff0@54
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |O|m|n|i| |c|o|m|p|l|e|t|i|o|n| |(|^|O|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |3| +0#0000000&@34
diff --git a/src/testdir/dumps/Test_pum_with_special_characters_12.dump b/src/testdir/dumps/Test_pum_with_special_characters_12.dump
new file mode 100644 (file)
index 0000000..5807526
--- /dev/null
@@ -0,0 +1,12 @@
+|l+0&#ffffff0|o|c|a|l| |a| |=| |f|u|n|c| |(|)| @57
+@2|l|o|c|a|l| |b| |=| |f|u|n|c| |(|)| @55
+@75
+@2|e|n|d> @69
+|e|n|d| @71
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|4|,|5|-|6| @8|A|l@1| 
index 63f0016dce346a840eb9a9a6952428212f88bef8..82d2ef0be4b5b9c600280dfe8964eb484be75c41 100644 (file)
@@ -1946,6 +1946,23 @@ func Test_pum_complete_with_special_characters()
   call VerifyScreenDump(buf, 'Test_pum_with_special_characters_08', {})
   call term_sendkeys(buf, "\<C-E>\<Esc>")
 
+  call term_sendkeys(buf, ":setlocal autoindent tabstop=2 shiftwidth=2\<CR>")
+  call term_sendkeys(buf, "Slocal a = \<C-X>\<C-O>")
+  call TermWait(buf, 50)
+  call VerifyScreenDump(buf, 'Test_pum_with_special_characters_09', {})
+
+  call term_sendkeys(buf, "\<C-Y>")
+  call TermWait(buf, 50)
+  call VerifyScreenDump(buf, 'Test_pum_with_special_characters_10', {})
+
+  call term_sendkeys(buf, "\<ESC>kAlocal b = \<C-X>\<C-O>")
+  call TermWait(buf, 50)
+  call VerifyScreenDump(buf, 'Test_pum_with_special_characters_11', {})
+
+  call term_sendkeys(buf, "\<C-Y>")
+  call TermWait(buf, 50)
+  call VerifyScreenDump(buf, 'Test_pum_with_special_characters_12', {})
+
   call StopVimInTerminal(buf)
 endfunc
 
index 5652fc34d34ae4c969db0633c6e01714e8a4832e..0adb6521deaad89c82b785f9a5eda648f1bb2c72 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1145,
 /**/
     1144,
 /**/
index 2ebc8fe0228472f9d7a98db354a3d1ae725a15e6..da2835c1c4d8099bba1331d1f3aec464e3328cfa 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -1175,12 +1175,13 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
 #define INSCHAR_COM_LIST 16    // format comments with list/2nd line indent
 
 // flags for open_line()
-#define OPENLINE_DELSPACES  0x01    // delete spaces after cursor
-#define OPENLINE_DO_COM            0x02    // format comments
-#define OPENLINE_KEEPTRAIL  0x04    // keep trailing spaces
-#define OPENLINE_MARKFIX    0x08    // fix mark positions
-#define OPENLINE_COM_LIST   0x10    // format comments with list/2nd line indent
-#define OPENLINE_FORMAT            0x20    // formatting long comment
+#define OPENLINE_DELSPACES     0x01    // delete spaces after cursor
+#define OPENLINE_DO_COM                0x02    // format comments
+#define OPENLINE_KEEPTRAIL     0x04    // keep trailing spaces
+#define OPENLINE_MARKFIX       0x08    // fix mark positions
+#define OPENLINE_COM_LIST      0x10    // format comments with list/2nd line indent
+#define OPENLINE_FORMAT                0x20    // formatting long comment
+#define OPENLINE_FORCE_INDENT  0x40    // use second_line_indent without indent logic
 
 // There are five history tables:
 #define HIST_CMD       0       // colon commands