Skip to content

Commit

Permalink
add reload all buffers command
Browse files Browse the repository at this point in the history
  • Loading branch information
Kl4rry committed Jul 20, 2024
1 parent 4e1e3c6 commit 6b4686f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions crates/ferrite-core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,21 @@ impl Engine {
self.palette.set_error(err)
};
}
Command::ReloadAll => {
for buffer in self.workspace.buffers.values_mut() {
if buffer.file().is_some() && buffer.is_dirty() {
self.palette
.set_error(format!("`{}` is dirty cannot reload", buffer.name()));
continue;
}

if buffer.file().is_some() {
if let Err(err) = buffer.reload() {
self.palette.set_error(err);
}
}
}
}
Command::Goto(line) => {
let PaneKind::Buffer(buffer_id) = self.workspace.panes.get_current_pane()
else {
Expand Down
1 change: 1 addition & 0 deletions crates/ferrite-core/src/palette/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub enum Command {
Pwd,
New(Option<PathBuf>),
Reload,
ReloadAll,
Logger,
ForceQuit,
Quit,
Expand Down
2 changes: 2 additions & 0 deletions crates/ferrite-core/src/palette/cmd_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn parse_cmd(input: &str) -> Result<Command, CommandParseError> {
("git-diff", [..]) => Command::GitDiff,
("pwd", [..]) => Command::Pwd,
("reload", [..]) => Command::Reload,
("reload-all", [..]) => Command::ReloadAll,
("logger", [..]) => Command::Logger,
("quit!", [..]) => Command::ForceQuit,
("quit", [..]) => Command::Quit,
Expand Down Expand Up @@ -126,6 +127,7 @@ static COMMANDS: Lazy<Vec<CommandTemplate>> = Lazy::new(|| {
CommandTemplate::new("git-reload", None, true),
CommandTemplate::new("git-diff", None, true),
CommandTemplate::new("reload", None, true).add_alias("r"),
CommandTemplate::new("reload-all", None, true),
CommandTemplate::new("logger", None, true).add_alias("log"),
CommandTemplate::new("quit!", None, true).add_alias("q!"),
CommandTemplate::new("quit", None, true).add_alias("q"),
Expand Down

0 comments on commit 6b4686f

Please sign in to comment.