Skip to content

Commit

Permalink
Migrate manual mode changes to switch_to
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacdonald committed Mar 6, 2024
1 parent 733fbd1 commit 1bb8ceb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
17 changes: 11 additions & 6 deletions src/commands/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::commands::{self, Result};
use crate::errors::*;
use crate::input::Key;
use crate::models::application::modes::ConfirmMode;
use crate::models::application::{Application, ClipboardContent, Mode};
use crate::models::application::{Application, ClipboardContent, Mode, ModeKey};
use crate::util;
use crate::util::token::{adjacent_token_position, Direction};
use scribe::buffer::{Buffer, Position, Range, Token};
Expand Down Expand Up @@ -204,8 +203,11 @@ pub fn close(app: &mut Application) -> Result {
app.workspace.close_current_buffer();
} else {
// Display a confirmation prompt before closing a modified buffer.
let confirm_mode = ConfirmMode::new(close);
app.mode = Mode::Confirm(confirm_mode);
app.switch_to(ModeKey::Confirm);
match app.mode {
Mode::Confirm(ref mut mode) => mode.command = close,
_ => (),
}
}

Ok(())
Expand Down Expand Up @@ -249,8 +251,11 @@ pub fn close_others(app: &mut Application) -> Result {

if modified_buffer {
// Display a confirmation prompt before closing a modified buffer.
let confirm_mode = ConfirmMode::new(close_others_confirm);
app.mode = Mode::Confirm(confirm_mode);
app.switch_to(ModeKey::Confirm);
match app.mode {
Mode::Confirm(ref mut mode) => mode.command = close_others_confirm,
_ => (),
}
break;
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/path.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::commands::{self, Result};
use crate::errors::*;
use crate::input::Key;
use crate::models::application::{Application, Mode};
use crate::models::application::{Application, Mode, ModeKey};
use std::path::PathBuf;

pub fn push_char(app: &mut Application) -> Result {
Expand Down Expand Up @@ -51,7 +51,7 @@ pub fn accept_path(app: &mut Application) -> Result {
app.workspace
.update_current_syntax()
.chain_err(|| BUFFER_SYNTAX_UPDATE_FAILED)?;
app.mode = Mode::Normal;
app.switch_to(ModeKey::Normal);

if save_on_accept {
commands::buffer::save(app)
Expand Down
11 changes: 3 additions & 8 deletions src/commands/search_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@ use crate::errors::*;
use crate::input::Key;
use crate::models::application::modes::open::DisplayablePath;
use crate::models::application::modes::SearchSelectMode;
use crate::models::application::{Application, Mode};
use std::mem;
use crate::models::application::{Application, Mode, ModeKey};

pub fn accept(app: &mut Application) -> Result {
// Consume the application mode. This is necessary because the selection in
// command mode needs to run against the application, but we can't hold the
// reference to the selection and lend the app mutably to it at the time.
let mut app_mode = mem::replace(&mut app.mode, Mode::Normal);

match app_mode {
match app.mode {
Mode::Command(ref mode) => {
let selection = mode.selection().ok_or("No command selected")?;

Expand Down Expand Up @@ -76,6 +70,7 @@ pub fn accept(app: &mut Application) -> Result {
_ => bail!("Can't accept selection outside of search select mode."),
}

app.switch_to(ModeKey::Normal);
commands::view::scroll_cursor_to_center(app).ok();

Ok(())
Expand Down

0 comments on commit 1bb8ceb

Please sign in to comment.