File tree Expand file tree Collapse file tree 3 files changed +30
-19
lines changed Expand file tree Collapse file tree 3 files changed +30
-19
lines changed Original file line number Diff line number Diff line change @@ -247,19 +247,8 @@ impl Component for Markdown {
247
247
248
248
// TODO: account for tab width
249
249
let max_text_width = ( viewport. 0 - padding) . min ( 120 ) ;
250
- let mut text_width = 0 ;
251
- let mut height = padding;
252
- for content in contents {
253
- height += 1 ;
254
- let content_width = content. width ( ) as u16 ;
255
- if content_width > max_text_width {
256
- text_width = max_text_width;
257
- height += content_width / max_text_width;
258
- } else if content_width > text_width {
259
- text_width = content_width;
260
- }
261
- }
250
+ let ( width, height) = crate :: ui:: text:: required_size ( & contents, max_text_width) ;
262
251
263
- Some ( ( text_width + padding, height) )
252
+ Some ( ( width + padding * 2 , height) )
264
253
}
265
254
}
Original file line number Diff line number Diff line change @@ -389,21 +389,27 @@ impl Prompt {
389
389
if let Some ( doc) = ( self . doc_fn ) ( & self . line ) {
390
390
let mut text = ui:: Text :: new ( doc. to_string ( ) ) ;
391
391
392
+ let max_width = BASE_WIDTH * 3 ;
393
+ let padding = 1 ;
394
+
392
395
let viewport = area;
396
+
397
+ let ( _width, height) = ui:: text:: required_size ( & text. contents , max_width) ;
398
+
393
399
let area = viewport. intersection ( Rect :: new (
394
400
completion_area. x ,
395
- completion_area. y . saturating_sub ( 3 ) ,
396
- BASE_WIDTH * 3 ,
397
- 3 ,
401
+ completion_area. y . saturating_sub ( height + padding * 2 ) ,
402
+ max_width ,
403
+ height + padding * 2 ,
398
404
) ) ;
399
405
400
406
let background = theme. get ( "ui.help" ) ;
401
407
surface. clear_with ( area, background) ;
402
408
403
409
text. render (
404
410
area. inner ( & Margin {
405
- vertical : 1 ,
406
- horizontal : 1 ,
411
+ vertical : padding ,
412
+ horizontal : padding ,
407
413
} ) ,
408
414
surface,
409
415
cx,
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use tui::buffer::Buffer as Surface;
4
4
use helix_view:: graphics:: Rect ;
5
5
6
6
pub struct Text {
7
- contents : tui:: text:: Text < ' static > ,
7
+ pub ( crate ) contents : tui:: text:: Text < ' static > ,
8
8
size : ( u16 , u16 ) ,
9
9
viewport : ( u16 , u16 ) ,
10
10
}
@@ -49,3 +49,19 @@ impl Component for Text {
49
49
Some ( self . size )
50
50
}
51
51
}
52
+
53
+ pub fn required_size ( text : & tui:: text:: Text , max_text_width : u16 ) -> ( u16 , u16 ) {
54
+ let mut text_width = 0 ;
55
+ let mut height = 0 ;
56
+ for content in & text. lines {
57
+ height += 1 ;
58
+ let content_width = content. width ( ) as u16 ;
59
+ if content_width > max_text_width {
60
+ text_width = max_text_width;
61
+ height += content_width / max_text_width;
62
+ } else if content_width > text_width {
63
+ text_width = content_width;
64
+ }
65
+ }
66
+ ( text_width, height)
67
+ }
You can’t perform that action at this time.
0 commit comments