diff --git a/src/components/changes.rs b/src/components/changes.rs index 45f87b5c..6f7067c1 100644 --- a/src/components/changes.rs +++ b/src/components/changes.rs @@ -236,11 +236,6 @@ impl Component for ChangesComponent { some_selection, self.focused(), )); - out.push(CommandInfo::new( - commands::COMMIT_OPEN_EDITOR, - !self.is_empty(), - self.focused() || force_all, - )); out.push( CommandInfo::new( commands::COMMIT_OPEN, @@ -271,15 +266,6 @@ impl Component for ChangesComponent { .push_back(InternalEvent::OpenCommit); Ok(true) } - keys::OPEN_COMMIT_EDITOR - if !self.is_working_dir - && !self.is_empty() => - { - self.queue - .borrow_mut() - .push_back(InternalEvent::SuspendPolling); - Ok(true) - } keys::STATUS_STAGE_FILE => { try_or_popup!( self, diff --git a/src/components/commit.rs b/src/components/commit.rs index 91743926..6bb2f93d 100644 --- a/src/components/commit.rs +++ b/src/components/commit.rs @@ -5,8 +5,7 @@ use super::{ use crate::{ get_app_config_path, keys, queue::{InternalEvent, NeedsUpdate, Queue}, - strings, - strings::{commands, COMMIT_EDITOR_MSG}, + strings::{self, commands}, ui::style::SharedTheme, }; use anyhow::{anyhow, Result}; @@ -67,6 +66,12 @@ impl Component for CommitComponent { self.can_amend(), true, )); + + out.push(CommandInfo::new( + commands::COMMIT_OPEN_EDITOR, + true, + true, + )); } visibility_blocking(self) @@ -88,6 +93,12 @@ impl Component for CommitComponent { self.amend()?; } + keys::OPEN_COMMIT_EDITOR => { + self.queue + .borrow_mut() + .push_back(InternalEvent::SuspendPolling); + } + _ => (), }; @@ -137,9 +148,15 @@ impl CommitComponent { let mut config_path: PathBuf = get_app_config_path()?; config_path.push(COMMIT_MSG_FILE_NAME); - let mut file = File::create(&config_path)?; - file.write_all(COMMIT_EDITOR_MSG.as_bytes())?; - drop(file); + { + //TODO: use a tmpfile here + let mut file = File::create(&config_path)?; + file.write_fmt(format_args!( + "{}\n", + self.input.get_text() + ))?; + file.write_all(strings::COMMIT_EDITOR_MSG.as_bytes())?; + } let mut editor = env::var("GIT_EDTIOR") .ok() @@ -156,9 +173,8 @@ impl CommitComponent { })?; io::stdout().execute(LeaveAlternateScreen)?; - defer! { - io::stdout().execute(EnterAlternateScreen).expect("failed to reset terminal"); + io::stdout().execute(EnterAlternateScreen).expect("reset terminal"); } Command::new(command) @@ -168,6 +184,7 @@ impl CommitComponent { let mut message = String::new(); + //TODO: see above let mut file = File::open(&config_path)?; file.read_to_string(&mut message)?; drop(file); @@ -184,9 +201,9 @@ impl CommitComponent { }) .collect(); - if !message.chars().all(char::is_whitespace) { - return self.commit_msg(message); - } + let message = message.trim().to_string(); + + self.input.set_text(message); Ok(()) } diff --git a/src/keys.rs b/src/keys.rs index 8bd98837..119bcb76 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -33,7 +33,7 @@ pub const EXIT_POPUP: KeyEvent = no_mod(KeyCode::Esc); pub const CLOSE_MSG: KeyEvent = no_mod(KeyCode::Enter); pub const OPEN_COMMIT: KeyEvent = no_mod(KeyCode::Char('c')); pub const OPEN_COMMIT_EDITOR: KeyEvent = - with_mod(KeyCode::Char('C'), KeyModifiers::SHIFT); + with_mod(KeyCode::Char('e'), KeyModifiers::CONTROL); pub const OPEN_HELP: KeyEvent = no_mod(KeyCode::Char('h')); pub const MOVE_LEFT: KeyEvent = no_mod(KeyCode::Left); pub const MOVE_RIGHT: KeyEvent = no_mod(KeyCode::Right); diff --git a/src/strings.rs b/src/strings.rs index edb047d3..e58b09ae 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -15,9 +15,8 @@ pub static COMMIT_TITLE: &str = "Commit"; pub static COMMIT_TITLE_AMEND: &str = "Commit (Amend)"; pub static COMMIT_MSG: &str = "type commit message.."; pub static COMMIT_EDITOR_MSG: &str = r##" -# Enter your commit message -# Lines starting with '#' will be ignored -# Empty commit message will abort the commit"##; +# Edit your commit message +# Lines starting with '#' will be ignored"##; pub static STASH_POPUP_TITLE: &str = "Stash"; pub static STASH_POPUP_MSG: &str = "type name (optional)"; pub static CONFIRM_TITLE_RESET: &str = "Reset"; @@ -155,7 +154,7 @@ pub mod commands { ); /// pub static COMMIT_OPEN_EDITOR: CommandText = CommandText::new( - "Commit editor [C]", + "Open editor [^e]", "open commit editor (available in non-empty stage)", CMD_GROUP_COMMIT, );