Skip to content

Commit

Permalink
Switch to normal mode following text reflow (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacdonald authored May 17, 2024
1 parent 3317b96 commit 3fc34c7
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/commands/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Range, Error> {
let buf = app
.workspace
Expand Down

0 comments on commit 3fc34c7

Please sign in to comment.