summaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-05-07 05:19:58 +0000
committerBlaž Hrastnik2021-05-07 05:19:58 +0000
commit7c915dc0651f2cd69bc40adca027729c3b12f4e3 (patch)
tree0885df668617196cb1413f02faa8419f17a24b22 /helix-term/src/commands.rs
parentf8844c68116cbbb1f24c49a5a7da95da7963616e (diff)
Add the :new command, don't crash if saving without filename.
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs20
1 files changed, 10 insertions, 10 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index a273fc6f..eab9397c 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -42,7 +42,6 @@ pub struct Context<'a> {
pub callback: Option<crate::compositor::Callback>,
pub on_next_key_callback: Option<Box<dyn FnOnce(&mut Context, KeyEvent)>>,
pub callbacks: &'a mut LspCallbacks,
- pub status_msg: Option<String>,
}
impl<'a> Context<'a> {
@@ -97,11 +96,6 @@ impl<'a> Context<'a> {
});
self.callbacks.push(callback);
}
-
- // TODO: allow &'static str?
- pub fn set_status(&mut self, msg: String) {
- self.status_msg = Some(msg);
- }
}
/// A command is a function that takes the current state and a count, and does a side-effect on the
@@ -852,6 +846,8 @@ pub fn command_mode(cx: &mut Context) {
}
}, // completion
move |editor: &mut Editor, input: &str, event: PromptEvent| {
+ use helix_view::editor::Action;
+
if event != PromptEvent::Validate {
return;
}
@@ -863,16 +859,20 @@ pub fn command_mode(cx: &mut Context) {
editor.close(editor.view().id);
}
["o", path] | ["open", path] => {
- use helix_view::editor::Action;
editor.open(path.into(), Action::Replace);
}
["w"] | ["write"] => {
- // TODO: non-blocking via save() command
let id = editor.view().doc;
let doc = &mut editor.documents[id];
+ if doc.path().is_none() {
+ editor.set_error("cannot write a buffer without a filename".to_string());
+ return;
+ }
tokio::spawn(doc.save());
}
-
+ ["new"] => {
+ editor.new_file(Action::Replace);
+ }
_ => (),
}
},
@@ -1585,7 +1585,7 @@ pub fn yank(cx: &mut Context) {
register::set(reg, values);
- cx.set_status(msg)
+ cx.editor.set_status(msg)
}
#[derive(Copy, Clone)]