summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-01-24 18:44:50 +0100
committerqkzk <qu3nt1n@gmail.com>2023-01-24 18:44:50 +0100
commit05cf2f910a19f0d0dbebf9fc28d37434ab9406c1 (patch)
tree9c6476a0b454d6f9ad5dba86268937524148d886
parentb8a77cbe8fc945adfe1ba129348d187507e41b10 (diff)
refactor tree next & prevtree-up-down
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/preview.rs38
3 files changed, 10 insertions, 32 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7004af7..5fbb2c2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -935,7 +935,7 @@ dependencies = [
[[package]]
name = "fm-tui"
-version = "0.1.12"
+version = "0.1.14"
dependencies = [
"chrono",
"clap 4.0.32",
diff --git a/Cargo.toml b/Cargo.toml
index 01d50fe..ff738a2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "fm-tui"
-version = "0.1.12"
+version = "0.1.14"
authors = ["Quentin Konieczko <qu3nt1n@gmail.com>"]
edition = "2021"
license-file = "LICENSE.txt"
diff --git a/src/preview.rs b/src/preview.rs
index f27cb7f..149bad3 100644
--- a/src/preview.rs
+++ b/src/preview.rs
@@ -10,7 +10,6 @@ use std::slice::Iter;
use content_inspector::{inspect, ContentType};
use image::imageops::FilterType;
use image::{ImageBuffer, Rgb};
-use log::info;
use pdf_extract;
use syntect::easy::HighlightLines;
use syntect::highlighting::{Style, ThemeSet};
@@ -578,23 +577,10 @@ impl Directory {
/// Select the "next" element of the tree if any.
/// This is the element immediatly below the current one.
pub fn select_next(&mut self, colors: &Colors) -> FmResult<()> {
- let step = 1;
- if self.selected_index + step < self.content.len() {
- self.selected_index += step;
+ if self.selected_index + 1 < self.content.len() {
+ self.selected_index += 1;
}
- self.tree.position = self.tree.position_from_index(self.selected_index);
- let (_, _, node) = self.tree.select_from_position()?;
- self.tree.current_node = node;
- let res: usize;
- (res, self.content) = self.tree.into_navigable_content(colors);
- info!(
- "index: {} res: {} position {:?} node {}",
- self.selected_index,
- res,
- self.tree.position,
- self.tree.current_node.filename()
- );
- Ok(())
+ self.update_tree_from_index(colors)
}
/// Select the previous sibling if any.
@@ -603,22 +589,14 @@ impl Directory {
if self.selected_index > 0 {
self.selected_index -= 1;
}
+ self.update_tree_from_index(colors)
+ }
+
+ fn update_tree_from_index(&mut self, colors: &Colors) -> FmResult<()> {
self.tree.position = self.tree.position_from_index(self.selected_index);
- info!(
- "index: {} position {:?}",
- self.selected_index, self.tree.position
- );
let (_, _, node) = self.tree.select_from_position()?;
self.tree.current_node = node;
- let res: usize;
- (res, self.content) = self.tree.into_navigable_content(colors);
- info!(
- "index: {} res: {} position {:?} node {}",
- self.selected_index,
- res,
- self.tree.position,
- self.tree.current_node.filename()
- );
+ (_, self.content) = self.tree.into_navigable_content(colors);
Ok(())
}