Browse Source

Fix (hopefully) the scrolling logic

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
c66b99272f
1 changed files with 11 additions and 11 deletions
  1. 11
    11
      src/hci/mucurses/widgets/editbox.c

+ 11
- 11
src/hci/mucurses/widgets/editbox.c View File

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

Loading…
Cancel
Save