Makes the current_focus field private to limit usage to its setters and getters

pull/704/head
Ahmed ElSamhaa 2 months ago
parent 01606e0e60
commit 4aa367ca7c

@ -754,7 +754,7 @@ impl App {
focus.as_ref().map(PathBuf::from), focus.as_ref().map(PathBuf::from),
self.directory_buffer self.directory_buffer
.as_ref() .as_ref()
.map(|d| d.scroll_state.current_focus) .map(|d| d.scroll_state.get_focus())
.unwrap_or(0), .unwrap_or(0),
) { ) {
Ok(dir) => self.set_directory(dir), Ok(dir) => self.set_directory(dir),
@ -825,15 +825,15 @@ impl App {
let bounded = self.config.general.enforce_bounded_index_navigation; let bounded = self.config.general.enforce_bounded_index_navigation;
if let Some(dir) = self.directory_buffer_mut() { if let Some(dir) = self.directory_buffer_mut() {
if dir.scroll_state.current_focus == 0 { if dir.scroll_state.get_focus() == 0 {
if bounded { if bounded {
dir.scroll_state.set_focus(dir.scroll_state.current_focus); dir.scroll_state.set_focus(dir.scroll_state.get_focus());
} else { } else {
dir.scroll_state.set_focus(dir.total.saturating_sub(1)); dir.scroll_state.set_focus(dir.total.saturating_sub(1));
} }
} else { } else {
dir.scroll_state dir.scroll_state
.set_focus(dir.scroll_state.current_focus.saturating_sub(1)); .set_focus(dir.scroll_state.get_focus().saturating_sub(1));
}; };
}; };
Ok(self) Ok(self)
@ -887,7 +887,7 @@ impl App {
} }
dir.scroll_state dir.scroll_state
.set_focus(dir.scroll_state.current_focus.saturating_sub(index)); .set_focus(dir.scroll_state.get_focus().saturating_sub(index));
if let Some(n) = self.focused_node() { if let Some(n) = self.focused_node() {
self.history = history.push(n.absolute_path.clone()); self.history = history.push(n.absolute_path.clone());
} }
@ -912,15 +912,15 @@ impl App {
let bounded = self.config.general.enforce_bounded_index_navigation; let bounded = self.config.general.enforce_bounded_index_navigation;
if let Some(dir) = self.directory_buffer_mut() { if let Some(dir) = self.directory_buffer_mut() {
if (dir.scroll_state.current_focus + 1) == dir.total { if (dir.scroll_state.get_focus() + 1) == dir.total {
if bounded { if bounded {
dir.scroll_state.set_focus(dir.scroll_state.current_focus); dir.scroll_state.set_focus(dir.scroll_state.get_focus());
} else { } else {
dir.scroll_state.set_focus(0); dir.scroll_state.set_focus(0);
} }
} else { } else {
dir.scroll_state dir.scroll_state
.set_focus(dir.scroll_state.current_focus + 1); .set_focus(dir.scroll_state.get_focus() + 1);
} }
}; };
Ok(self) Ok(self)
@ -975,7 +975,7 @@ impl App {
dir.scroll_state.set_focus( dir.scroll_state.set_focus(
dir.scroll_state dir.scroll_state
.current_focus .get_focus()
.saturating_add(index) .saturating_add(index)
.min(dir.total.saturating_sub(1)), .min(dir.total.saturating_sub(1)),
); );

@ -4,7 +4,7 @@ use time::OffsetDateTime;
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct ScrollState { pub struct ScrollState {
pub current_focus: usize, current_focus: usize,
pub last_focus: Option<usize>, pub last_focus: Option<usize>,
pub skipped_rows: usize, pub skipped_rows: usize,
} }
@ -18,6 +18,10 @@ impl ScrollState {
self.current_focus = current_focus; self.current_focus = current_focus;
} }
pub fn get_focus(&self) -> usize {
self.current_focus
}
pub fn calc_skipped_rows( pub fn calc_skipped_rows(
&mut self, &mut self,
height: usize, height: usize,

@ -89,7 +89,7 @@ fn call(
let focus_index = app let focus_index = app
.directory_buffer .directory_buffer
.as_ref() .as_ref()
.map(|d| d.scroll_state.current_focus) .map(|d| d.scroll_state.get_focus())
.unwrap_or_default() .unwrap_or_default()
.to_string(); .to_string();
@ -281,7 +281,7 @@ impl Runner {
self.focused_path, self.focused_path,
app.directory_buffer app.directory_buffer
.as_ref() .as_ref()
.map(|d| d.scroll_state.current_focus) .map(|d| d.scroll_state.get_focus())
.unwrap_or(0), .unwrap_or(0),
tx_msg_in.clone(), tx_msg_in.clone(),
); );
@ -433,7 +433,7 @@ impl Runner {
.map(|n| n.relative_path.clone().into()), .map(|n| n.relative_path.clone().into()),
app.directory_buffer app.directory_buffer
.as_ref() .as_ref()
.map(|d| d.scroll_state.current_focus) .map(|d| d.scroll_state.get_focus())
.unwrap_or(0), .unwrap_or(0),
tx_msg_in.clone(), tx_msg_in.clone(),
); );
@ -448,7 +448,7 @@ impl Runner {
.map(|n| n.relative_path.clone().into()), .map(|n| n.relative_path.clone().into()),
app.directory_buffer app.directory_buffer
.as_ref() .as_ref()
.map(|d| d.scroll_state.current_focus) .map(|d| d.scroll_state.get_focus())
.unwrap_or(0), .unwrap_or(0),
tx_msg_in.clone(), tx_msg_in.clone(),
); );

@ -748,7 +748,7 @@ fn draw_table(
.skip(dir.scroll_state.skipped_rows) .skip(dir.scroll_state.skipped_rows)
.take(height) .take(height)
.map(|(index, node)| { .map(|(index, node)| {
let is_focused = dir.scroll_state.current_focus == index; let is_focused = dir.scroll_state.get_focus() == index;
let is_selected = app let is_selected = app
.selection .selection
@ -777,12 +777,12 @@ fn draw_table(
let node_type = app_config.node_types.get(node); let node_type = app_config.node_types.get(node);
let (relative_index, is_before_focus, is_after_focus) = let (relative_index, is_before_focus, is_after_focus) =
match dir.scroll_state.current_focus.cmp(&index) { match dir.scroll_state.get_focus().cmp(&index) {
Ordering::Greater => { Ordering::Greater => {
(dir.scroll_state.current_focus - index, true, false) (dir.scroll_state.get_focus() - index, true, false)
} }
Ordering::Less => { Ordering::Less => {
(index - dir.scroll_state.current_focus, false, true) (index - dir.scroll_state.get_focus(), false, true)
} }
Ordering::Equal => (0, false, false), Ordering::Equal => (0, false, false),
}; };

Loading…
Cancel
Save