зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-08 08:25:51 +03:00
fix weird behavior on empty placeholder
Этот коммит содержится в:
@@ -61,7 +61,7 @@ pub struct TextArea<'a> {
|
|||||||
#[cfg(feature = "search")]
|
#[cfg(feature = "search")]
|
||||||
search: Search,
|
search: Search,
|
||||||
alignment: Alignment,
|
alignment: Alignment,
|
||||||
pub(crate) placeholder: Option<String>,
|
pub(crate) placeholder: String,
|
||||||
pub(crate) placeholder_style: Style,
|
pub(crate) placeholder_style: Style,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +160,7 @@ impl<'a> TextArea<'a> {
|
|||||||
#[cfg(feature = "search")]
|
#[cfg(feature = "search")]
|
||||||
search: Search::default(),
|
search: Search::default(),
|
||||||
alignment: Alignment::Left,
|
alignment: Alignment::Left,
|
||||||
placeholder: None,
|
placeholder: String::new(),
|
||||||
placeholder_style: Style::default().fg(Color::DarkGray),
|
placeholder_style: Style::default().fg(Color::DarkGray),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1240,7 +1240,7 @@ impl<'a> TextArea<'a> {
|
|||||||
|
|
||||||
/// sets the placeholder text
|
/// sets the placeholder text
|
||||||
pub fn set_placeholder(&mut self, placeholder: String) {
|
pub fn set_placeholder(&mut self, placeholder: String) {
|
||||||
self.placeholder = Some(placeholder);
|
self.placeholder = placeholder;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_placeholder_style(&mut self, style: Style) {
|
pub fn set_placeholder_style(&mut self, style: Style) {
|
||||||
|
|||||||
@@ -119,11 +119,11 @@ impl<'a> Widget for Renderer<'a> {
|
|||||||
let top_row = next_scroll_top(top_row, cursor.0 as u16, height);
|
let top_row = next_scroll_top(top_row, cursor.0 as u16, height);
|
||||||
let top_col = next_scroll_top(top_col, cursor.1 as u16, width);
|
let top_col = next_scroll_top(top_col, cursor.1 as u16, width);
|
||||||
|
|
||||||
let (text, style) = match &self.0.placeholder {
|
let (text, style) = if !self.0.placeholder.is_empty() && self.0.is_empty() {
|
||||||
Some(text) if self.0.is_empty() => {
|
let text = Text::from(self.0.placeholder.as_str());
|
||||||
(Text::from(text.as_str()), self.0.placeholder_style) // When a placeholder is set and no text is in textarea
|
(text, self.0.placeholder_style)
|
||||||
}
|
} else {
|
||||||
_ => (self.text(top_row as usize, height as usize), self.0.style()),
|
(self.text(top_row as usize, height as usize), self.0.style())
|
||||||
};
|
};
|
||||||
|
|
||||||
// To get fine control over the text color and the surrrounding block they have to be rendered separately
|
// To get fine control over the text color and the surrrounding block they have to be rendered separately
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user