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

Signed-off-by: Ron Yorston <[email protected]>
---
 editors/vi.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/editors/vi.c b/editors/vi.c
index 68a376b92..270a35840 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -3895,9 +3895,16 @@ static void do_cmd(int c)
                break;
        case 'r':                       // r- replace the current char with 
user input
                c1 = get_one_char();    // get the replacement char
-               if (*dot != '\n') {
-                       dot = text_hole_delete(dot, dot, ALLOW_UNDO);
-                       dot = char_insert(dot, c1, ALLOW_UNDO_CHAIN);
+               if (c1 != 27) {
+                       if (end_line(dot) - dot < (cmdcnt ?: 1)) {
+                               indicate_error();
+                               goto dc6;
+                       }
+                       do {
+                               dot = text_hole_delete(dot, dot, allow_undo);
+                               allow_undo = ALLOW_UNDO_CHAIN;
+                               dot = char_insert(dot, c1, allow_undo);
+                       } while (--cmdcnt > 0);
                        dot_left();
                }
                end_cmd_q();    // stop adding to q
-- 
2.30.2

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to