From c47d3bd271bf188c4c51b51d465b3afc5da4e641 Mon Sep 17 00:00:00 2001 From: Jordan MacDonald Date: Fri, 17 May 2024 10:42:37 -0400 Subject: [PATCH] Switch to normal mode following text reflow --- src/commands/selection.rs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/commands/selection.rs b/src/commands/selection.rs index 6a3f4af2..34094d79 100644 --- a/src/commands/selection.rs +++ b/src/commands/selection.rs @@ -50,6 +50,21 @@ pub fn select_all(app: &mut Application) -> Result { Ok(()) } +pub fn justify(app: &mut Application) -> Result { + let range = sel_to_range(app)?; + let buffer = app.workspace.current_buffer.as_mut().unwrap(); + + let limit = match app.preferences.borrow().line_length_guides()[..] { + [first, ..] => first, + [] => bail!("Justification requires a line_length_guide."), + }; + + buffer.start_operation_group(); + Reflow::new(buffer, range, limit)?.apply()?; + buffer.end_operation_group(); + application::switch_to_normal_mode(app) +} + fn copy_to_clipboard(app: &mut Application) -> Result { let buffer = app .workspace @@ -82,22 +97,6 @@ fn copy_to_clipboard(app: &mut Application) -> Result { Ok(()) } -pub fn justify(app: &mut Application) -> Result { - let range = sel_to_range(app)?; - let buffer = app.workspace.current_buffer.as_mut().unwrap(); - - let limit = match app.preferences.borrow().line_length_guides()[..] { - [first, ..] => first, - [] => bail!("Justification requires a line_length_guide."), - }; - - buffer.start_operation_group(); - Reflow::new(buffer, range, limit)?.apply()?; - buffer.end_operation_group(); - - Ok(()) -} - fn sel_to_range(app: &mut Application) -> std::result::Result { let buf = app .workspace