vi: allow 'r' command to be aborted, repeated
Make the 'r' command behave more like vi: - abort the command if ESC is entered after the 'r'; - allow a repeat count to be entered before the 'r'; - if the repeat count exceeds the space available on the line don't change any characters and issue an alert. function old new delta do_cmd 4679 4746 +67 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 67/0) Total: 67 bytes v2: Don't break build when FEATURE_VI_UNDO is disabled. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
b18c7bf702
commit
fe76569daa
15
editors/vi.c
15
editors/vi.c
@ -3920,9 +3920,18 @@ static void do_cmd(int c)
|
|||||||
break;
|
break;
|
||||||
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 (c1 != 27) {
|
||||||
dot = text_hole_delete(dot, dot, ALLOW_UNDO);
|
if (end_line(dot) - dot < (cmdcnt ?: 1)) {
|
||||||
dot = char_insert(dot, c1, ALLOW_UNDO_CHAIN);
|
indicate_error();
|
||||||
|
goto dc6;
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
dot = text_hole_delete(dot, dot, allow_undo);
|
||||||
|
#if ENABLE_FEATURE_VI_UNDO
|
||||||
|
allow_undo = ALLOW_UNDO_CHAIN;
|
||||||
|
#endif
|
||||||
|
dot = char_insert(dot, c1, allow_undo);
|
||||||
|
} while (--cmdcnt > 0);
|
||||||
dot_left();
|
dot_left();
|
||||||
}
|
}
|
||||||
end_cmd_q(); // stop adding to q
|
end_cmd_q(); // stop adding to q
|
||||||
|
Loading…
Reference in New Issue
Block a user