|
@@ -35,7 +35,7 @@
|
35
|
35
|
*/
|
36
|
36
|
static void insert_delete ( struct edit_string *string, size_t delete_len,
|
37
|
37
|
const char *insert_text ) {
|
38
|
|
- size_t old_len, max_delete_len, insert_len, max_insert_len;
|
|
38
|
+ size_t old_len, max_delete_len, insert_len, max_insert_len, new_len;
|
39
|
39
|
|
40
|
40
|
/* Calculate lengths */
|
41
|
41
|
old_len = strlen ( string->buf );
|
|
@@ -47,6 +47,11 @@ static void insert_delete ( struct edit_string *string, size_t delete_len,
|
47
|
47
|
max_insert_len = ( ( string->len - 1 ) - ( old_len - delete_len ) );
|
48
|
48
|
if ( insert_len > max_insert_len )
|
49
|
49
|
insert_len = max_insert_len;
|
|
50
|
+ new_len = ( old_len - delete_len + insert_len );
|
|
51
|
+
|
|
52
|
+ /* Fill in edit history */
|
|
53
|
+ string->mod_start = string->cursor;
|
|
54
|
+ string->mod_end = ( ( new_len > old_len ) ? new_len : old_len );
|
50
|
55
|
|
51
|
56
|
/* Move data following the cursor */
|
52
|
57
|
memmove ( ( string->buf + string->cursor + insert_len ),
|
|
@@ -113,10 +118,19 @@ static void kill_eol ( struct edit_string *string ) {
|
113
|
118
|
* zero, otherwise it will return the original key.
|
114
|
119
|
*
|
115
|
120
|
* This function does not update the display in any way.
|
|
121
|
+ *
|
|
122
|
+ * The string's edit history will be updated to allow the caller to
|
|
123
|
+ * efficiently bring the display into sync with the string content.
|
116
|
124
|
*/
|
117
|
125
|
int edit_string ( struct edit_string *string, int key ) {
|
118
|
126
|
int retval = 0;
|
119
|
127
|
|
|
128
|
+ /* Prepare edit history */
|
|
129
|
+ string->last_cursor = string->cursor;
|
|
130
|
+ string->mod_start = string->cursor;
|
|
131
|
+ string->mod_end = string->cursor;
|
|
132
|
+
|
|
133
|
+ /* Interpret key */
|
120
|
134
|
if ( ( key >= 0x20 ) && ( key <= 0x7e ) ) {
|
121
|
135
|
/* Printable character; insert at current position */
|
122
|
136
|
insert_character ( string, key );
|