aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/change.c9
-rw-r--r--src/nvim/change.h13
-rw-r--r--src/nvim/insexpand.c3
-rw-r--r--test/functional/ui/popupmenu_spec.lua46
-rw-r--r--test/old/testdir/test_popup.vim17
5 files changed, 78 insertions, 10 deletions
diff --git a/src/nvim/change.c b/src/nvim/change.c
index 27749576d7..31962b52ce 100644
--- a/src/nvim/change.c
+++ b/src/nvim/change.c
@@ -1071,6 +1071,7 @@ bool copy_indent(int size, char *src)
/// 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
@@ -1162,9 +1163,11 @@ bool open_line(int dir, int flags, int second_line_indent, bool *did_do_comment)
trunc_line = true;
}
- // 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) {
+ if ((flags & OPENLINE_FORCE_INDENT)) {
+ newindent = second_line_indent;
+ } else if (curbuf->b_p_ai || do_si) {
+ // If 'autoindent' and/or 'smartindent' is set, try to figure out what
+ // indent to use for the new line.
// count white space on current line
newindent = indent_size_ts(saved_line, curbuf->b_p_ts, curbuf->b_p_vts_array);
if (newindent == 0 && !(flags & OPENLINE_COM_LIST)) {
diff --git a/src/nvim/change.h b/src/nvim/change.h
index bd1094d57e..084d66c51f 100644
--- a/src/nvim/change.h
+++ b/src/nvim/change.h
@@ -7,12 +7,13 @@
/// flags for open_line()
enum {
- OPENLINE_DELSPACES = 0x01, ///< delete spaces after cursor
- OPENLINE_DO_COM = 0x02, ///< format comments
- OPENLINE_KEEPTRAIL = 0x04, ///< keep trailing spaces
- OPENLINE_MARKFIX = 0x08, ///< fix mark positions
- OPENLINE_COM_LIST = 0x10, ///< format comments with list/2nd line indent
- OPENLINE_FORMAT = 0x20, ///< formatting long comment
+ OPENLINE_DELSPACES = 0x01, ///< delete spaces after cursor
+ OPENLINE_DO_COM = 0x02, ///< format comments
+ OPENLINE_KEEPTRAIL = 0x04, ///< keep trailing spaces
+ OPENLINE_MARKFIX = 0x08, ///< fix mark positions
+ OPENLINE_COM_LIST = 0x10, ///< format comments with list/2nd line indent
+ OPENLINE_FORMAT = 0x20, ///< formatting long comment
+ OPENLINE_FORCE_INDENT = 0x40, ///< use second_line_indent without indent logic
};
#ifdef INCLUDE_GENERATED_DECLARATIONS
diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c
index fdae0d7327..0c06447233 100644
--- a/src/nvim/insexpand.c
+++ b/src/nvim/insexpand.c
@@ -3833,6 +3833,7 @@ static void ins_compl_expand_multiple(char *str)
{
char *start = str;
char *curr = str;
+ int base_indent = get_indent();
while (*curr != NUL) {
if (*curr == '\n') {
// Insert the text chunk before newline
@@ -3841,7 +3842,7 @@ static void ins_compl_expand_multiple(char *str)
}
// 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/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua
index 0a28ea2d0a..fe093b67d5 100644
--- a/test/functional/ui/popupmenu_spec.lua
+++ b/test/functional/ui/popupmenu_spec.lua
@@ -6042,6 +6042,52 @@ describe('builtin popupmenu', function()
{2:-- }{5:match 1 of 3} |
]])
feed('<C-E><ESC>')
+
+ command('setlocal autoindent shiftwidth=2 tabstop=2')
+ feed('Slocal a = <C-X><C-O>')
+ screen:expect([[
+ local a = {8:func ()} |
+ {8: } |
+ {8:end}^ |
+ {1:~ }{s: function () }{1: }|
+ {1:~ }{n: foobar }{1: }|
+ {1:~ }{n: 你好^@ ^@我好 }{1: }|
+ {1:~ }|*13
+ {2:-- }{5:match 1 of 3} |
+ ]])
+
+ feed('<C-Y>')
+ screen:expect([[
+ local a = {8:func ()} |
+ {8: } |
+ end^ |
+ {1:~ }|*16
+ {2:-- INSERT --} |
+ ]])
+
+ feed('<ESC>kAlocal b = <C-X><C-O>')
+ screen:expect([[
+ local a = {8:func ()} |
+ local b = {8:func ()} |
+ {8: } |
+ {8: end}^ |
+ end {s: function () } |
+ {1:~ }{n: foobar }{1: }|
+ {1:~ }{n: 你好^@ ^@我好 }{1: }|
+ {1:~ }|*12
+ {2:-- }{5:match 1 of 3} |
+ ]])
+
+ feed('<C-Y>')
+ screen:expect([[
+ local a = {8:func ()} |
+ local b = {8:func ()} |
+ {8: } |
+ end^ |
+ end |
+ {1:~ }|*14
+ {2:-- INSERT --} |
+ ]])
end)
end
end
diff --git a/test/old/testdir/test_popup.vim b/test/old/testdir/test_popup.vim
index 41b694860c..0b88fd1dba 100644
--- a/test/old/testdir/test_popup.vim
+++ b/test/old/testdir/test_popup.vim
@@ -1937,6 +1937,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