@@ -23,7 +23,6 @@ use tui::{
23
23
} ;
24
24
use utils:: { ItemBatch , LogEntry } ;
25
25
26
- static ELEMENTS_PER_LINE : usize = 10 ;
27
26
static SLICE_SIZE : usize = 1200 ;
28
27
///
29
28
pub struct Revlog {
@@ -169,7 +168,8 @@ impl Revlog {
169
168
tags : Option < String > ,
170
169
theme : & Theme ,
171
170
) {
172
- let count_before = txt. len ( ) ;
171
+ const ELEMENTS_PER_LINE : usize = 10 ;
172
+
173
173
txt. reserve ( ELEMENTS_PER_LINE ) ;
174
174
175
175
let splitter_txt = Cow :: from ( " " ) ;
@@ -205,24 +205,29 @@ impl Revlog {
205
205
theme. text ( true , selected) ,
206
206
) ) ;
207
207
txt. push ( Text :: Raw ( Cow :: from ( "\n " ) ) ) ;
208
-
209
- assert_eq ! ( txt. len( ) - count_before, ELEMENTS_PER_LINE ) ;
210
208
}
211
209
212
- fn get_text ( & self ) -> Vec < Text > {
210
+ fn get_text ( & self , height : usize ) -> Vec < Text > {
213
211
let selection = self . relative_selection ( ) ;
214
212
215
213
let mut txt = Vec :: new ( ) ;
216
214
217
- for ( idx, e) in self . items . items . iter ( ) . enumerate ( ) {
215
+ for ( idx, e) in self
216
+ . items
217
+ . items
218
+ . iter ( )
219
+ . skip ( self . scroll_top )
220
+ . take ( height)
221
+ . enumerate ( )
222
+ {
218
223
let tag = if let Some ( tags) = self . tags . get ( & e. hash ) {
219
224
Some ( tags. join ( " " ) )
220
225
} else {
221
226
None
222
227
} ;
223
228
Self :: add_entry (
224
229
e,
225
- idx == selection,
230
+ idx + self . scroll_top == selection,
226
231
& mut txt,
227
232
tag,
228
233
& self . theme ,
@@ -261,20 +266,15 @@ impl DrawableComponent for Revlog {
261
266
) ;
262
267
263
268
f. render_widget (
264
- Paragraph :: new (
265
- self . get_text ( )
266
- . iter ( )
267
- . skip ( self . scroll_top * ELEMENTS_PER_LINE )
268
- . take ( height_in_lines * ELEMENTS_PER_LINE ) ,
269
- )
270
- . block (
271
- Block :: default ( )
272
- . borders ( Borders :: ALL )
273
- . title ( title. as_str ( ) )
274
- . border_style ( self . theme . block ( true ) )
275
- . title_style ( self . theme . title ( true ) ) ,
276
- )
277
- . alignment ( Alignment :: Left ) ,
269
+ Paragraph :: new ( self . get_text ( height_in_lines) . iter ( ) )
270
+ . block (
271
+ Block :: default ( )
272
+ . borders ( Borders :: ALL )
273
+ . title ( title. as_str ( ) )
274
+ . border_style ( self . theme . block ( true ) )
275
+ . title_style ( self . theme . title ( true ) ) ,
276
+ )
277
+ . alignment ( Alignment :: Left ) ,
278
278
area,
279
279
) ;
280
280
}
0 commit comments