Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: element style of ui.Text was not applied to the entire area #2093

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions yazi-plugin/src/elements/text.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::mem;

use ansi_to_tui::IntoText;
use mlua::{ExternalError, ExternalResult, FromLua, IntoLua, Lua, Table, UserData, Value};
use ratatui::widgets::Widget;
Expand Down Expand Up @@ -56,8 +58,11 @@ impl Text {
trans: impl Fn(yazi_config::popup::Position) -> ratatui::layout::Rect,
) {
let rect = self.area.transform(trans);
let p: ratatui::widgets::Paragraph = self.into();
p.render(rect, buf);
if self.wrap == WRAP_NO {
self.inner.render(rect, buf);
} else {
ratatui::widgets::Paragraph::from(self).render(rect, buf);
}
}
}

Expand Down Expand Up @@ -114,15 +119,18 @@ impl From<Text> for ratatui::text::Text<'static> {
}

impl From<Text> for ratatui::widgets::Paragraph<'static> {
fn from(value: Text) -> Self {
let align = value.inner.alignment.unwrap_or_default();
let mut p = ratatui::widgets::Paragraph::new(value.inner);
fn from(mut value: Text) -> Self {
let align = value.inner.alignment.take();
let style = mem::take(&mut value.inner.style);

let mut p = ratatui::widgets::Paragraph::new(value.inner).style(style);
if let Some(align) = align {
p = p.alignment(align);
}
if value.wrap != WRAP_NO {
p = p.wrap(ratatui::widgets::Wrap { trim: value.wrap == WRAP_TRIM });
}

p.alignment(align)
p
}
}

Expand Down
Loading