Procházet zdrojové kódy

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

tags/v0.9.3
Michael Brown před 18 roky
rodič
revize
66007fa448
2 změnil soubory, kde provedl 27 přidání a 4 odebrání
  1. 15
    1
      src/hci/editstring.c
  2. 12
    3
      src/include/gpxe/editstring.h

+ 15
- 1
src/hci/editstring.c Zobrazit soubor

@@ -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 );

+ 12
- 3
src/include/gpxe/editstring.h Zobrazit soubor

@@ -1,5 +1,5 @@
1
-#ifndef _EDITSTRING_H
2
-#define _EDITSTRING_H
1
+#ifndef _GPXE_EDITSTRING_H
2
+#define _GPXE_EDITSTRING_H
3 3
 
4 4
 /** @file
5 5
  *
@@ -15,8 +15,17 @@ struct edit_string {
15 15
 	size_t len;
16 16
 	/** Cursor position */
17 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 29
 extern int edit_string ( struct edit_string *string, int key );
21 30
 
22
-#endif /* _EDITSTRING_H */
31
+#endif /* _GPXE_EDITSTRING_H */

Načítá se…
Zrušit
Uložit