regedit: don't expand single line text field buffer with cursor movement
authorChris Davis <cd.rattan@gmail.com>
Sat, 9 Aug 2014 05:25:50 +0000 (22:25 -0700)
committerMichael Adam <obnox@samba.org>
Wed, 1 Oct 2014 12:32:09 +0000 (14:32 +0200)
Signed-off-by: Chris Davis <cd.rattan@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
source3/utils/regedit_dialog.c

index b807c4eda691cc0ad31b54560f64389f2e9f8081..b5ab400ed01504793d55af8311c76fa6a8aac5b5 100644 (file)
@@ -721,8 +721,18 @@ struct dialog_section_text_field {
        unsigned opts;
        FIELD *field[2];
        FORM *form;
+       int length;
 };
 
+static int get_cursor_col(struct dialog_section_text_field *field)
+{
+       int col;
+
+       col = field->form->curcol + field->form->begincol;
+
+       return col;
+}
+
 static WERROR text_field_create(struct dialog *dia,
                                struct dialog_section *section)
 {
@@ -775,12 +785,20 @@ static void text_field_on_input(struct dialog *dia,
 
        switch (c) {
        case KEY_BACKSPACE:
+               if (text_field->length) {
+                       text_field->length--;
+               }
                form_driver(text_field->form, REQ_DEL_PREV);
                break;
+       case '\x7f':
        case KEY_DC:
+               if (text_field->length) {
+                       text_field->length--;
+               }
                form_driver(text_field->form, REQ_DEL_CHAR);
                break;
        default:
+               text_field->length++;
                form_driver(text_field->form, c);
                break;
        }
@@ -829,7 +847,10 @@ static bool text_field_on_right(struct dialog *dia,
        struct dialog_section_text_field *text_field =
                talloc_get_type_abort(section, struct dialog_section_text_field);
 
-       form_driver(text_field->form, REQ_RIGHT_CHAR);
+       if (section->nlines > 1 ||
+           get_cursor_col(text_field) < text_field->length) {
+               form_driver(text_field->form, REQ_RIGHT_CHAR);
+       }
 
        return true;
 }
@@ -841,6 +862,7 @@ static enum dialog_action text_field_on_enter(struct dialog *dia,
                talloc_get_type_abort(section, struct dialog_section_text_field);
 
        if (section->nlines > 1) {
+               text_field->length += text_field->form->cols;
                form_driver(text_field->form, REQ_NEW_LINE);
                return DIALOG_IGNORE;
        }
@@ -911,6 +933,7 @@ void dialog_section_text_field_set(struct dialog_section *section,
        struct dialog_section_text_field *text_field =
                talloc_get_type_abort(section, struct dialog_section_text_field);
 
+       text_field->length = strlen(s);
        set_field_buffer(text_field->field[0], 0, s);
 }