Some kind of refactoring
This commit is contained in:
61
src/services/help_nav.rs
Normal file
61
src/services/help_nav.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
use crate::model::docs;
|
||||
use crate::state::{HelpFocus, UiState};
|
||||
|
||||
pub fn toggle_focus(ui: &mut UiState) {
|
||||
ui.help_focus = match ui.help_focus {
|
||||
HelpFocus::Topics => HelpFocus::Content,
|
||||
HelpFocus::Content => HelpFocus::Topics,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn next_topic(ui: &mut UiState, n: usize) {
|
||||
let count = docs::topic_count();
|
||||
ui.help_topic = (ui.help_topic + n) % count;
|
||||
}
|
||||
|
||||
pub fn prev_topic(ui: &mut UiState, n: usize) {
|
||||
let count = docs::topic_count();
|
||||
ui.help_topic = (ui.help_topic + count - (n % count)) % count;
|
||||
}
|
||||
|
||||
pub fn scroll_down(ui: &mut UiState, n: usize) {
|
||||
let s = ui.help_scroll_mut();
|
||||
*s = s.saturating_add(n);
|
||||
}
|
||||
|
||||
pub fn scroll_up(ui: &mut UiState, n: usize) {
|
||||
let s = ui.help_scroll_mut();
|
||||
*s = s.saturating_sub(n);
|
||||
}
|
||||
|
||||
pub fn activate_search(ui: &mut UiState) {
|
||||
ui.help_search_active = true;
|
||||
}
|
||||
|
||||
pub fn clear_search(ui: &mut UiState) {
|
||||
ui.help_search_query.clear();
|
||||
ui.help_search_active = false;
|
||||
}
|
||||
|
||||
pub fn search_input(ui: &mut UiState, c: char) {
|
||||
ui.help_search_query.push(c);
|
||||
if let Some((topic, line)) = docs::find_match(&ui.help_search_query) {
|
||||
ui.help_topic = topic;
|
||||
ui.help_scrolls[topic] = line;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn search_backspace(ui: &mut UiState) {
|
||||
ui.help_search_query.pop();
|
||||
if ui.help_search_query.is_empty() {
|
||||
return;
|
||||
}
|
||||
if let Some((topic, line)) = docs::find_match(&ui.help_search_query) {
|
||||
ui.help_topic = topic;
|
||||
ui.help_scrolls[topic] = line;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn search_confirm(ui: &mut UiState) {
|
||||
ui.help_search_active = false;
|
||||
}
|
||||
Reference in New Issue
Block a user