Browse Source

Provide an edit history to allow caller to efficiently update display.

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
66007fa448
2 changed files with 27 additions and 4 deletions
  1. 15
    1
      src/hci/editstring.c
  2. 12
    3
      src/include/gpxe/editstring.h

+ 15
- 1
src/hci/editstring.c View File

35
  */
35
  */
36
 static void insert_delete ( struct edit_string *string, size_t delete_len,
36
 static void insert_delete ( struct edit_string *string, size_t delete_len,
37
 			    const char *insert_text ) {
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
 	/* Calculate lengths */
40
 	/* Calculate lengths */
41
 	old_len = strlen ( string->buf );
41
 	old_len = strlen ( string->buf );
47
 	max_insert_len = ( ( string->len - 1 ) - ( old_len - delete_len ) );
47
 	max_insert_len = ( ( string->len - 1 ) - ( old_len - delete_len ) );
48
 	if ( insert_len > max_insert_len )
48
 	if ( insert_len > max_insert_len )
49
 		insert_len = max_insert_len;
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
 	/* Move data following the cursor */
56
 	/* Move data following the cursor */
52
 	memmove ( ( string->buf + string->cursor + insert_len ),
57
 	memmove ( ( string->buf + string->cursor + insert_len ),
113
  * zero, otherwise it will return the original key.
118
  * zero, otherwise it will return the original key.
114
  *
119
  *
115
  * This function does not update the display in any way.
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
 int edit_string ( struct edit_string *string, int key ) {
125
 int edit_string ( struct edit_string *string, int key ) {
118
 	int retval = 0;
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
 	if ( ( key >= 0x20 ) && ( key <= 0x7e ) ) {
134
 	if ( ( key >= 0x20 ) && ( key <= 0x7e ) ) {
121
 		/* Printable character; insert at current position */
135
 		/* Printable character; insert at current position */
122
 		insert_character ( string, key );
136
 		insert_character ( string, key );

+ 12
- 3
src/include/gpxe/editstring.h View File

1
-#ifndef _EDITSTRING_H
2
-#define _EDITSTRING_H
1
+#ifndef _GPXE_EDITSTRING_H
2
+#define _GPXE_EDITSTRING_H
3
 
3
 
4
 /** @file
4
 /** @file
5
  *
5
  *
15
 	size_t len;
15
 	size_t len;
16
 	/** Cursor position */
16
 	/** Cursor position */
17
 	unsigned int cursor;
17
 	unsigned int cursor;
18
+
19
+	/* The following items are the edit history */
20
+
21
+	/** Last cursor position */
22
+	unsigned int last_cursor;
23
+	/** Start of modified portion of string */
24
+	unsigned int mod_start;
25
+	/** End of modified portion of string */
26
+	unsigned int mod_end;
18
 };
27
 };
19
 
28
 
20
 extern int edit_string ( struct edit_string *string, int key );
29
 extern int edit_string ( struct edit_string *string, int key );
21
 
30
 
22
-#endif /* _EDITSTRING_H */
31
+#endif /* _GPXE_EDITSTRING_H */

Loading…
Cancel
Save