diff options
author | glepnir <glephunter@gmail.com> | 2025-02-25 14:30:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-25 06:30:21 +0000 |
commit | c9a2b16c4842b5c61af1f57a66637fbd94efba24 (patch) | |
tree | 992f3dd3c008296ff88e2f8ad430594b0128fadf /src | |
parent | 095c0876c2010d6160df37cf057f2d0ad2c4501f (diff) | |
download | rneovim-c9a2b16c4842b5c61af1f57a66637fbd94efba24.tar.gz rneovim-c9a2b16c4842b5c61af1f57a66637fbd94efba24.tar.bz2 rneovim-c9a2b16c4842b5c61af1f57a66637fbd94efba24.zip |
vim-patch:9.1.1145: multi-line completion has wrong indentation for last line (#32625)
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: vim/vim#16614
https://github.com/vim/vim/commit/5090a1fecb86c44be83d55e139ed79b7785fa090
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/change.c | 9 | ||||
-rw-r--r-- | src/nvim/change.h | 13 | ||||
-rw-r--r-- | src/nvim/insexpand.c | 3 |
3 files changed, 15 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++; |