diff options
Diffstat (limited to 'helix-view')
-rw-r--r-- | helix-view/src/editor.rs | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 630ea5cf..affe87dd 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -834,18 +834,6 @@ impl Default for SearchConfig { } } -pub struct Motion(pub Box<dyn Fn(&mut Editor)>); -impl Motion { - pub fn run(&self, e: &mut Editor) { - (self.0)(e) - } -} -impl std::fmt::Debug for Motion { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str("motion") - } -} - #[derive(Debug, Clone, Default)] pub struct Breakpoint { pub id: Option<usize>, @@ -910,8 +898,7 @@ pub struct Editor { pub auto_pairs: Option<AutoPairs>, pub idle_timer: Pin<Box<Sleep>>, - pub last_motion: Option<Motion>, - + last_motion: Option<Motion>, pub last_completion: Option<CompleteAction>, pub exit_code: i32, @@ -945,6 +932,8 @@ pub struct Editor { pub completion_request_handle: Option<oneshot::Sender<()>>, } +pub type Motion = Box<dyn Fn(&mut Editor)>; + pub type RedrawHandle = (Arc<Notify>, Arc<RwLock<()>>); #[derive(Debug)] @@ -1051,6 +1040,19 @@ impl Editor { } } + pub fn apply_motion<F: Fn(&mut Self) + 'static>(&mut self, motion: F) { + motion(self); + self.last_motion = Some(Box::new(motion)); + } + + pub fn repeat_last_motion(&mut self, count: usize) { + if let Some(motion) = self.last_motion.take() { + for _ in 0..count { + motion(self); + } + self.last_motion = Some(motion); + } + } /// Current editing mode for the [`Editor`]. pub fn mode(&self) -> Mode { self.mode |