mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-09-10 14:02:15 +00:00
move cursor into separated mod
This commit is contained in:
parent
247c7babed
commit
c521ae4f5d
@ -47,7 +47,7 @@ impl Navigation {
|
||||
back,
|
||||
forward,
|
||||
g_box,
|
||||
model: RefCell::new(Model::new(Vec::new())), // @TODO
|
||||
model: RefCell::new(Model::new(Vec::new())), // @TODO option?
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ impl Navigation {
|
||||
pub fn update(&self, matches: Vec<(TextIter, TextIter)>) {
|
||||
self.back.update(!matches.is_empty());
|
||||
self.forward.update(!matches.is_empty());
|
||||
let _ = self.model.replace(Model::new(matches));
|
||||
self.model.replace(Model::new(matches));
|
||||
}
|
||||
|
||||
pub fn back(&self, subject: &Subject) -> Option<(TextIter, TextIter)> {
|
||||
|
@ -1,33 +1,5 @@
|
||||
struct Cursor {
|
||||
current: usize,
|
||||
last: usize,
|
||||
}
|
||||
|
||||
impl Cursor {
|
||||
pub fn back(&mut self) {
|
||||
self.current = if self.current > 0 {
|
||||
self.current - 1
|
||||
} else {
|
||||
self.last
|
||||
}
|
||||
}
|
||||
|
||||
pub fn next(&mut self) {
|
||||
self.current = if self.current < self.last {
|
||||
self.current + 1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_index(&self) -> usize {
|
||||
if self.current > 0 {
|
||||
self.current - 1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
mod cursor;
|
||||
use cursor::Cursor;
|
||||
|
||||
pub struct Model<T> {
|
||||
cursor: Cursor,
|
||||
@ -37,10 +9,7 @@ pub struct Model<T> {
|
||||
impl<T> Model<T> {
|
||||
pub fn new(vector: Vec<T>) -> Self {
|
||||
Self {
|
||||
cursor: Cursor {
|
||||
current: 0,
|
||||
last: vector.len(),
|
||||
},
|
||||
cursor: Cursor::new(vector.len()),
|
||||
vector,
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
pub struct Cursor {
|
||||
current: usize,
|
||||
last: usize,
|
||||
}
|
||||
|
||||
impl Cursor {
|
||||
pub fn new(len: usize) -> Self {
|
||||
Self {
|
||||
current: 0,
|
||||
last: len,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn back(&mut self) {
|
||||
self.current = if self.current > 0 {
|
||||
self.current - 1
|
||||
} else {
|
||||
self.last
|
||||
}
|
||||
}
|
||||
|
||||
pub fn next(&mut self) {
|
||||
self.current = if self.current < self.last {
|
||||
self.current + 1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_index(&self) -> usize {
|
||||
if self.current > 0 {
|
||||
self.current - 1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user