summaryrefslogtreecommitdiff
path: root/src/systems/helpdoc/helpdoc_viewer.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-03-20 22:21:56 +0800
committer魏曹先生 <1992414357@qq.com>2026-03-20 22:21:56 +0800
commitab6be7968b25afb57fc428695693484ad8576718 (patch)
treee4af27964f195a18a678844dbe71c0aaa182b5dc /src/systems/helpdoc/helpdoc_viewer.rs
parent6b22f7b7694fce530f84ba94c65c057450cca626 (diff)
Refactor code to use modern Rust idioms and fix clippy lints
Diffstat (limited to 'src/systems/helpdoc/helpdoc_viewer.rs')
-rw-r--r--src/systems/helpdoc/helpdoc_viewer.rs28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/systems/helpdoc/helpdoc_viewer.rs b/src/systems/helpdoc/helpdoc_viewer.rs
index 560b827..db7f2c6 100644
--- a/src/systems/helpdoc/helpdoc_viewer.rs
+++ b/src/systems/helpdoc/helpdoc_viewer.rs
@@ -251,10 +251,10 @@ impl HelpdocViewer {
while !should_exit {
self.draw()?;
- if event::poll(std::time::Duration::from_millis(100))? {
- if let Event::Key(key) = event::read()? {
- should_exit = self.handle_key(key);
- }
+ if event::poll(std::time::Duration::from_millis(100))?
+ && let Event::Key(key) = event::read()?
+ {
+ should_exit = self.handle_key(key);
}
}
@@ -330,6 +330,7 @@ impl HelpdocViewer {
}
/// Recursively draw tree node
+ #[allow(clippy::too_many_arguments)]
fn draw_tree_node(
&self,
node: &DocTreeNode,
@@ -442,8 +443,8 @@ impl HelpdocViewer {
}
// Display scroll position indicator
- if content_lines.len() > height as usize && content_lines.len() > 0 {
- let scroll_percent = if content_lines.len() > 0 {
+ if content_lines.len() > height as usize && !content_lines.is_empty() {
+ let scroll_percent = if !content_lines.is_empty() {
(scroll_pos * 100) / content_lines.len()
} else {
0
@@ -580,16 +581,13 @@ impl HelpdocViewer {
/// Select current item
fn select_item(&mut self) {
- match self.focus {
- FocusArea::Tree => {
- // Update current document to the one selected in tree view
- if let Some(doc) = self.doc_tree.flat_docs.get(self.tree_selection_index) {
- self.current_doc = doc.clone();
- }
- // Switch focus to content area
- self.focus = FocusArea::Content;
+ if self.focus == FocusArea::Tree {
+ // Update current document to the one selected in tree view
+ if let Some(doc) = self.doc_tree.flat_docs.get(self.tree_selection_index) {
+ self.current_doc = doc.clone();
}
- _ => {}
+ // Switch focus to content area
+ self.focus = FocusArea::Content;
}
}