Skip to content

Commit bb12ed0

Browse files
authored
[Fix] incorrect editor width (#101)
1 parent b034634 commit bb12ed0

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

core/src/components/command_line/command_line_header.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ use crate::{
66
render_error,
77
style::{ComponentStyle, RawComponentStyle, Size, Style},
88
},
9-
utils::{
10-
code::{calc_wh_with_min_width, CHAR_WIDTH},
11-
color::parse_hex_to_cosmic_color,
12-
},
9+
utils::color::parse_hex_to_cosmic_color,
1310
};
1411

1512
pub struct CommandLineHeader {
@@ -28,7 +25,11 @@ impl Component for CommandLineHeader {
2825
"{} {}",
2926
context.take_snapshot_params.command_output_config.prompt, self.full_command
3027
);
31-
let (w, h) = calc_wh_with_min_width(parsed_line.as_str(), CHAR_WIDTH, 20.);
28+
let (w, h) = context
29+
.font_renderer
30+
.lock()
31+
.unwrap()
32+
.measure_text(self.metrics, parsed_line.as_str());
3233

3334
Style::default().size(Size::Num(w), Size::Num(h))
3435
}

core/src/components/command_line/command_line_output.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::{
77
render_error,
88
style::{self, RawComponentStyle, Size, Style},
99
},
10-
utils::code::calc_wh_with_min_width,
1110
};
1211

1312
pub struct CommandLineOutput {
@@ -21,12 +20,12 @@ impl Component for CommandLineOutput {
2120
&self.children
2221
}
2322

24-
fn style(&self, _context: &ComponentContext) -> RawComponentStyle {
25-
let (w, h) = calc_wh_with_min_width(
26-
&self.ansi_text,
27-
self.metrics.font_size / 2.,
28-
self.metrics.line_height,
29-
);
23+
fn style(&self, context: &ComponentContext) -> RawComponentStyle {
24+
let (w, h) = context
25+
.font_renderer
26+
.lock()
27+
.unwrap()
28+
.measure_text(self.metrics, &self.ansi_text);
3029

3130
Style::default().size(Size::Num(w), Size::Num(h))
3231
}

core/src/components/editor/code.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ use crate::{
1111
style::{ComponentStyle, RawComponentStyle, Size, Style},
1212
},
1313
config::{self},
14-
utils::{
15-
code::{calc_wh_with_min_width, prepare_code, CHAR_WIDTH},
16-
highlight::Highlight,
17-
syntax_provider::SyntaxProvider,
18-
},
14+
utils::{code::prepare_code, highlight::Highlight, syntax_provider::SyntaxProvider},
1915
};
2016

2117
const FONT_SIZE: f32 = 12.5;
@@ -34,8 +30,12 @@ impl Component for Code {
3430
&self.children
3531
}
3632

37-
fn style(&self, _context: &ComponentContext) -> RawComponentStyle {
38-
let (w, h) = calc_wh_with_min_width(&self.value, CHAR_WIDTH, self.metrics.line_height);
33+
fn style(&self, context: &ComponentContext) -> RawComponentStyle {
34+
let (w, h) = context
35+
.font_renderer
36+
.lock()
37+
.unwrap()
38+
.measure_text(self.metrics, &self.value);
3939

4040
Style::default().size(Size::Num(w), Size::Num(h))
4141
}

0 commit comments

Comments
 (0)