Pārlūkot izejas kodu

Fix (hopefully) the scrolling logic

tags/v0.9.3
Michael Brown 18 gadus atpakaļ
vecāks
revīzija
c66b99272f
1 mainītis faili ar 11 papildinājumiem un 11 dzēšanām
  1. 11
    11
      src/hci/mucurses/widgets/editbox.c

+ 11
- 11
src/hci/mucurses/widgets/editbox.c Parādīt failu

@@ -62,31 +62,31 @@ void init_editbox ( struct edit_box *box, char *buf, size_t len,
62 62
 void draw_editbox ( struct edit_box *box ) {
63 63
 	size_t width = box->width;
64 64
 	char buf[ width + 1 ];
65
-	size_t keep_len;
66
-	signed int cursor_offset, underflow, overflow;
65
+	signed int cursor_offset, underflow, overflow, first;
67 66
 	size_t len;
68 67
 
69 68
 	/* Adjust starting offset so that cursor remains within box */
70 69
 	cursor_offset = ( box->string.cursor - box->first );
71
-	keep_len = strlen ( box->string.buf );
72
-	if ( keep_len > EDITBOX_MIN_CHARS )
73
-		keep_len = EDITBOX_MIN_CHARS;
74
-	underflow = ( keep_len - cursor_offset );
70
+	underflow = ( EDITBOX_MIN_CHARS - cursor_offset );
75 71
 	overflow = ( cursor_offset - ( width - 1 ) );
72
+	first = box->first;
76 73
 	if ( underflow > 0 ) {
77
-		box->first -= underflow;
74
+		first -= underflow;
75
+		if ( first < 0 )
76
+			first = 0;
78 77
 	} else if ( overflow > 0 ) {
79
-		box->first += overflow;
78
+		first += overflow;
80 79
 	}
81
-	cursor_offset = ( box->string.cursor - box->first );
80
+	box->first = first;
81
+	cursor_offset = ( box->string.cursor - first );
82 82
 
83 83
 	/* Construct underscore-padded string portion */
84 84
 	memset ( buf, '_', width );
85 85
 	buf[width] = '\0';
86
-	len = ( strlen ( box->string.buf ) - box->first );
86
+	len = ( strlen ( box->string.buf ) - first );
87 87
 	if ( len > width )
88 88
 		len = width;
89
-	memcpy ( buf, ( box->string.buf + box->first ), len );
89
+	memcpy ( buf, ( box->string.buf + first ), len );
90 90
 
91 91
 	/* Print box content and move cursor */
92 92
 	if ( ! box->win )

Notiek ielāde…
Atcelt
Saglabāt