Skip to content

Commit

Permalink
Merge pull request #159 from PeterJFB/feat/table-balancing
Browse files Browse the repository at this point in the history
131 Initial implementation of table balancing
  • Loading branch information
henriklovhaug authored Oct 18, 2024
2 parents 43cb069 + a7dd4b1 commit 981cf15
Show file tree
Hide file tree
Showing 8 changed files with 386 additions and 119 deletions.
29 changes: 10 additions & 19 deletions examples/demo.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::time::{Duration, Instant};

use crossterm;
use crossterm::event::{Event, KeyCode, KeyModifiers};
use crossterm::terminal;
use crossterm::terminal::{EnterAlternateScreen, LeaveAlternateScreen};
Expand Down Expand Up @@ -54,7 +53,7 @@ impl App {

fn scroll_down(&mut self) -> bool {
if let Some(markdown) = &self.markdown {
let len = markdown.content().len() as u16;
let len = markdown.height();
if self.area.height > len {
self.scroll = 0;
} else {
Expand All @@ -75,11 +74,7 @@ impl App {
fn draw(&mut self, frame: &mut Frame) {
self.area = frame.area();

self.markdown = Some(parser::parse_markdown(
None,
&CONTENT.to_string(),
self.area.width,
));
self.markdown = Some(parser::parse_markdown(None, CONTENT, self.area.width));

if let Some(markdown) = &mut self.markdown {
markdown.set_scroll(self.scroll);
Expand All @@ -92,19 +87,15 @@ impl App {
};

for child in markdown.children() {
match child {
Component::TextComponent(comp) => {
if comp.y_offset().saturating_sub(comp.scroll_offset()) >= area.height
|| (comp.y_offset() + comp.height())
.saturating_sub(comp.scroll_offset())
== 0
{
continue;
}

frame.render_widget(comp.clone(), area);
if let Component::TextComponent(comp) = child {
if comp.y_offset().saturating_sub(comp.scroll_offset()) >= area.height
|| (comp.y_offset() + comp.height()).saturating_sub(comp.scroll_offset())
== 0
{
continue;
}
_ => {}

frame.render_widget(comp.clone(), area);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/boxes/searchbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl SearchBox {
}

pub fn insert(&mut self, c: char) {
self.text.push_str(&c.to_string());
self.text.push(c);
self.cursor += 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/md.pest
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ italic = {
sentence = _{ (latex | code | link | bold_italic | italic | bold | strikethrough | normal+)+ }
t_sentence = _{ (!"|" ~ (latex | code | link | italic | bold | strikethrough | t_normal))+ }

table_cell = { "|" ~ WHITESPACE_S* ~ t_sentence+ ~ WHITESPACE_S* ~ ("|" ~ " "* ~ NEWLINE)? }
table_cell = { "|" ~ WHITESPACE_S* ~ t_sentence* ~ WHITESPACE_S* ~ ("|" ~ " "* ~ NEWLINE)? }
table_seperator = { ("|"? ~ (WHITESPACE_S | ":")* ~ "-"+ ~ (WHITESPACE_S | ":")* ~ "|") }

u_list = { indent ~ ("-" | "*") ~ WHITESPACE_S ~ sentence+ }
Expand Down
3 changes: 2 additions & 1 deletion src/nodes/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ impl ComponentRoot {
Component::TextComponent(comp) => Some(comp),
Component::Image(_) => None,
}) {
if index - count < comp.num_links() {
let link_inside_comp = index - count < comp.num_links();
if link_inside_comp {
comp.visually_select(index - count)?;
return Ok(comp.y_offset());
}
Expand Down
Loading

0 comments on commit 981cf15

Please sign in to comment.