Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to normal mode following text reflow #286

Merged
merged 1 commit into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading