Skip to content

Commit

Permalink
Fix link selection reset on layout change (#142)
Browse files Browse the repository at this point in the history
Changes made:
* fix: fix link index reset on layout change
  • Loading branch information
Builditluc authored Jan 22, 2023
1 parent 379007a commit ed7ccbe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ui/article/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ impl ArticleContent {
)
.wrap_lines();

self.link_handler = lines_wrapper.link_handler;
if let Some(ref mut link_handler) = self.link_handler {
link_handler.update(lines_wrapper.link_handler);
} else {
self.link_handler = lines_wrapper.link_handler;
}

self.rendered_lines = lines_wrapper.rendered_lines;

if let Some(ref header_y) = lines_wrapper.header_y {
Expand Down
17 changes: 17 additions & 0 deletions src/ui/article/links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ impl LinkHandler {
}
}

/// Updates the links while trying to save the currently selected link
pub fn update(&mut self, other: Option<LinkHandler>) {
if other.is_none() {
return;
}

let other = other.unwrap();

if let Some(current_link_id) = self.get_current_link() {
self.links = other.links;
self.set_current_link(current_link_id);
} else {
self.links = other.links;
self.current_link = other.current_link;
}
}

/// Returns the total number of registered links
pub fn registered_links(&self) -> usize {
self.links.len()
Expand Down
5 changes: 5 additions & 0 deletions src/ui/article/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ impl View for ArticleView {
// save the new size and compute the lines
self.last_size = size;
self.content.compute_lines(size);

debug!("current link id: {:?}", self.content.current_link());
debug!("current link pos: {:?}", self.content.current_link_pos());
}

fn required_size(&mut self, constraint: Vec2) -> Vec2 {
Expand Down Expand Up @@ -285,6 +288,8 @@ impl View for ArticleView {
self.scroll(Absolute::Down, move_amount);
}

debug!("link pos after selection: {:?}", current_link_pos);

EventResult::Consumed(None)
}
Event::Key(Key::Enter) if CONFIG.features.links => self.check_and_open_link(),
Expand Down

0 comments on commit ed7ccbe

Please sign in to comment.