mirror of
https://github.com/zaphar/sheetsui.git
synced 2025-07-23 05:19:48 -04:00
Compare commits
3 Commits
41e1d546df
...
0ddeadde37
Author | SHA1 | Date | |
---|---|---|---|
0ddeadde37 | |||
69b7fb5983 | |||
2bc95a3ef3 |
@ -11,6 +11,7 @@ pub struct Dialog<'w> {
|
||||
title: &'w str,
|
||||
bottom_title: &'w str,
|
||||
scroll: (u16, u16),
|
||||
// TODO(zaphar): Have a max margin?
|
||||
}
|
||||
|
||||
impl<'w> Dialog<'w> {
|
||||
@ -39,19 +40,23 @@ impl<'w> Widget for Dialog<'w> {
|
||||
Self: Sized,
|
||||
{
|
||||
// First find the center of the area.
|
||||
let content_width = self.content.width();
|
||||
let content_height = self.content.height();
|
||||
let vertical_margin = if ((content_height as u16) + 2) <= area.height {
|
||||
let content_width = 120 + 2;
|
||||
let content_height = (self.content.height() + 2) as u16;
|
||||
let vertical_margin = if content_height <= area.height {
|
||||
area.height
|
||||
.saturating_sub((content_height as u16) + 2)
|
||||
.saturating_sub(content_height as u16)
|
||||
.saturating_div(2)
|
||||
} else {
|
||||
area.height - 2
|
||||
2
|
||||
};
|
||||
let horizontal_margin = area
|
||||
let horizontal_margin = if content_width <= area.width {
|
||||
area
|
||||
.width
|
||||
.saturating_sub((content_width as u16) + 2)
|
||||
.saturating_div(2);
|
||||
.saturating_sub(content_width as u16)
|
||||
.saturating_div(2)
|
||||
} else {
|
||||
2
|
||||
};
|
||||
let [_, dialog_vertical, _] = Layout::vertical(vec![
|
||||
Constraint::Length(vertical_margin),
|
||||
Constraint::Fill(1),
|
||||
|
@ -172,6 +172,7 @@ impl Markdown {
|
||||
match tag {
|
||||
TagEnd::Heading { .. } => {
|
||||
lines.push(current_line);
|
||||
lines.push(Line::default()); // Add empty line after heading
|
||||
current_line = Line::default();
|
||||
state_stack.pop();
|
||||
}
|
||||
@ -339,8 +340,6 @@ impl Widget for Markdown {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use ratatui::text::Text;
|
||||
|
||||
#[test]
|
||||
fn test_empty_markdown() {
|
||||
let md = Markdown::from_str("");
|
||||
@ -361,15 +360,17 @@ mod tests {
|
||||
let md = Markdown::from_str("# Heading 1\n## Heading 2\n### Heading 3");
|
||||
let text = md.get_text();
|
||||
|
||||
// Should have 3 headings
|
||||
assert_eq!(text.lines.len(), 3);
|
||||
// Should have 3 headings and 6 lines
|
||||
assert_eq!(text.lines.len(), 6);
|
||||
|
||||
// Check content
|
||||
assert_eq!(text.lines[0].spans[0].content, "Heading 1");
|
||||
assert_eq!(text.lines[1].spans[0].content, "Heading 2");
|
||||
assert_eq!(text.lines[2].spans[0].content, "Heading 3");
|
||||
assert_eq!(text.lines[1].spans.len(), 0);
|
||||
assert_eq!(text.lines[2].spans[0].content, "Heading 2");
|
||||
assert_eq!(text.lines[3].spans.len(), 0);
|
||||
assert_eq!(text.lines[4].spans[0].content, "Heading 3");
|
||||
assert_eq!(text.lines[5].spans.len(), 0);
|
||||
|
||||
// Check styling (we can't directly check the style, but we can verify it's different)
|
||||
assert!(text.lines[0].style != text.lines[1].style);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user