-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: History and navigation via shortcuts. (#258)
* feat: Added history and navigation via shortcuts. Signed-off-by: konrad <kokos.kekse@gmail.com> * Fix: mute clippy complaint Co-authored-by: CosmicHorror <CosmicHorrorDev@pm.me> * Add: Vim like binding for Previous and Next file. Signed-off-by: konrad <kokos.kekse@gmail.com> --------- Signed-off-by: konrad <kokos.kekse@gmail.com> Co-authored-by: CosmicHorror <CosmicHorrorDev@pm.me>
- Loading branch information
1 parent
d134028
commit 15e7d49
Showing
6 changed files
with
134 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use smart_debug::SmartDebug; | ||
use std::path::PathBuf; | ||
|
||
#[derive(SmartDebug, Clone, PartialEq)] | ||
pub struct History { | ||
history: Vec<PathBuf>, | ||
index: usize, | ||
} | ||
|
||
impl History { | ||
pub fn new(path_buf: PathBuf) -> Self { | ||
History { | ||
history: vec![path_buf], | ||
index: 0, | ||
} | ||
} | ||
pub fn truncate(&mut self) { | ||
if self.index + 1 < self.history.len() { | ||
self.history.truncate(self.index + 1); | ||
} | ||
} | ||
pub fn append(&mut self, file_path: PathBuf) { | ||
self.history.push(file_path); | ||
self.index += 1; | ||
} | ||
pub fn get_path(&self) -> &PathBuf { | ||
self.history | ||
.get(self.index) | ||
.expect("History should be bound checked for all possible indexes.") | ||
} | ||
|
||
#[allow(clippy::should_implement_trait)] | ||
pub fn next(&mut self) -> Option<&PathBuf> { | ||
if self.index + 1 == self.history.len() { | ||
return None; | ||
} | ||
self.index += 1; | ||
Some(self.get_path()) | ||
} | ||
pub fn previous(&mut self) -> Option<&PathBuf> { | ||
if self.index == 0 { | ||
return None; | ||
} | ||
self.index -= 1; | ||
Some(self.get_path()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters