vi: fix replacement of single character with CR

Currently if the 'r' command is followed by a carriage return a
literal CR replaces the current character.

Fix this so that:

- a new line is inserted
- the autoindent setting is respected
- the cursor is placed at the start of the new line

function                                             old     new   delta
do_cmd                                              5052    5060      +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 8/0)                 Total: 8 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Ron Yorston 2019-02-03 14:01:58 +00:00 committed by Denys Vlasenko
parent bb983f30e7
commit df4e3af9f7

View File

@ -4189,14 +4189,9 @@ static void do_cmd(int c)
case 'r': // r- replace the current char with user input case 'r': // r- replace the current char with user input
c1 = get_one_char(); // get the replacement char c1 = get_one_char(); // get the replacement char
if (*dot != '\n') { if (*dot != '\n') {
#if ENABLE_FEATURE_VI_UNDO dot = text_hole_delete(dot, dot, ALLOW_UNDO);
undo_push(dot, 1, UNDO_DEL); dot = char_insert(dot, c1, ALLOW_UNDO_CHAIN);
*dot = c1; dot_left();
undo_push(dot, 1, UNDO_INS_CHAIN);
#else
*dot = c1;
modified_count++;
#endif
} }
end_cmd_q(); // stop adding to q end_cmd_q(); // stop adding to q
break; break;