cursor.rs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. use crate::application::Application;
  2. use crate::errors::*;
  3. pub fn move_left(app: &mut Application) -> Result<()> {
  4. if let Some(ref mut buffer) = app.workspace.current_buffer {
  5. buffer.cursor.move_left();
  6. app.monitor.scroll_to_cursor(buffer)?;
  7. }
  8. Ok(())
  9. }
  10. pub fn move_right(app: &mut Application) -> Result<()> {
  11. if let Some(ref mut buffer) = app.workspace.current_buffer {
  12. buffer.cursor.move_right();
  13. app.monitor.scroll_to_cursor(buffer)?;
  14. }
  15. Ok(())
  16. }
  17. pub fn move_up(app: &mut Application) -> Result<()> {
  18. if let Some(ref mut buffer) = app.workspace.current_buffer {
  19. buffer.cursor.move_up();
  20. app.monitor.scroll_to_cursor(buffer)?;
  21. }
  22. Ok(())
  23. }
  24. pub fn move_down(app: &mut Application) -> Result<()> {
  25. if let Some(ref mut buffer) = app.workspace.current_buffer {
  26. buffer.cursor.move_down();
  27. app.monitor.scroll_to_cursor(buffer)?;
  28. }
  29. Ok(())
  30. }
  31. pub fn move_to_start_of_line(app: &mut Application) -> Result<()> {
  32. if let Some(ref mut buffer) = app.workspace.current_buffer {
  33. buffer.cursor.move_to_start_of_line();
  34. }
  35. Ok(())
  36. }