aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2022-03-18 11:29:53 +0000
committerDenys Vlasenko <vda.linux@googlemail.com>2022-06-26 19:38:28 +0200
commitaf3b585815de5af367995d6064d994394b46c928 (patch)
tree185ee176c0c7d472906e01e2d51b0628a0eec099
parent7d1c7d8337853ca99e6ec1150ac4b834cfed5cd3 (diff)
downloadbusybox-w32-af3b585815de5af367995d6064d994394b46c928.tar.gz
busybox-w32-af3b585815de5af367995d6064d994394b46c928.tar.bz2
busybox-w32-af3b585815de5af367995d6064d994394b46c928.zip
vi: fix regression in autoindent handling
Suppose autoindent is enabled and we have a line with an initial tab where we want to split the words onto separate lines: split the words One way to do this is with the sequence 'f r<CR>;r<CR>', but in BusyBox vi the result is: split he words This is a regression introduced by commit 9659a8db1 (vi: remove autoindent from otherwise empty lines). The amount of indentation is being recorded when the 'r' command inserts a newline but isn't subsequently reset. A fix is to only record the indent when in insert or replace mode. Proper handling of the 'o' and 'O' commands then requires them to switch to insert mode before calling char_insert() to insert a newline. function old new delta char_insert 884 891 +7 do_cmd 4243 4247 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 11/0) Total: 11 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/vi.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/editors/vi.c b/editors/vi.c
index 6fa0a4e18..5b86b0516 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -2227,7 +2227,10 @@ static char *char_insert(char *p, char c, int undo) // insert the char c at 'p'
2227 p--; // open above, indent before newly inserted NL 2227 p--; // open above, indent before newly inserted NL
2228 2228
2229 if (len) { 2229 if (len) {
2230 indentcol = col; 2230 // only record indent if in insert/replace mode or for
2231 // the 'o'/'O' commands, which are switched to insert
2232 // mode early.
2233 indentcol = cmd_mode != 0 ? col : 0;
2231 if (expandtab) { 2234 if (expandtab) {
2232 ntab = 0; 2235 ntab = 0;
2233 nspc = col; 2236 nspc = col;
@@ -4265,6 +4268,9 @@ static void do_cmd(int c)
4265 case 'o': // o- open an empty line below 4268 case 'o': // o- open an empty line below
4266 dot_end(); 4269 dot_end();
4267 dc3: 4270 dc3:
4271#if ENABLE_FEATURE_VI_SETOPTS
4272 cmd_mode = 1; // switch to insert mode early
4273#endif
4268 dot = char_insert(dot, '\n', ALLOW_UNDO); 4274 dot = char_insert(dot, '\n', ALLOW_UNDO);
4269 if (c == 'O' && !autoindent) { 4275 if (c == 'O' && !autoindent) {
4270 // done in char_insert() for 'O'+autoindent 4276 // done in char_insert() for 'O'+autoindent