aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorCole Helbling2021-11-15 15:30:45 +0000
committerGitHub2021-11-15 15:30:45 +0000
commitc638b6b60e69697b7e7957ed1af1ac071c41974b (patch)
tree1c724c7074e46f19b8595df2362648abecceecae /helix-term
parentcccc1949ebabcbc1b336f370847626c9d6774fbb (diff)
helix-term/commands: implement buffer-close (bc, bclose) (#1035)
* helix-view/view: impl method to remove document from jumps * helix-view/editor: impl close_document * helix-view/editor: remove close_buffer argument from `close` According to archseer, this was never implemented or used properly. Now that we have a proper "buffer close" function, we can get rid of this. * helix-term/commands: implement buffer-close (bc, bclose) This behaves the same as Kakoune's `delete-buffer` / `db` command: * With 3 files opened by the user with `:o ab`, `:o cd`, and `:o ef`: * `buffer-close` once closes `ef` and switches to `cd` * `buffer-close` again closes `cd` and switches to `ab` * `buffer-close` again closes `ab` and switches to a scratch buffer * With 3 files opened from the command line with `hx -- ab cd ef`: * `buffer-close` once closes `ab` and switches to `cd` * `buffer-close` again closes `cd` and switches to `ef` * `buffer-close` again closes `ef` and switches to a scratch buffer * With 1 file opened (`ab`): * `buffer-close` once closes `ab` and switches to a scratch buffer * `buffer-close` again closes the scratch buffer and switches to a new scratch buffer * helix-term/commands: implement buffer-close! (bclose!, bc!) Namely, if you have a document open in multiple splits, all the splits will be closed at the same time, leaving only splits without that document focused (or a scratch buffer if they were all focused on that buffer). * helix-view/tree: reset focus if Tree is empty
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs50
1 files changed, 42 insertions, 8 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 8c0a005c..c7aab726 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1700,8 +1700,7 @@ mod cmd {
buffers_remaining_impl(cx.editor)?
}
- cx.editor
- .close(view!(cx.editor).id, /* close_buffer */ false);
+ cx.editor.close(view!(cx.editor).id);
Ok(())
}
@@ -1711,8 +1710,7 @@ mod cmd {
_args: &[&str],
_event: PromptEvent,
) -> anyhow::Result<()> {
- cx.editor
- .close(view!(cx.editor).id, /* close_buffer */ false);
+ cx.editor.close(view!(cx.editor).id);
Ok(())
}
@@ -1730,6 +1728,28 @@ mod cmd {
Ok(())
}
+ fn buffer_close(
+ cx: &mut compositor::Context,
+ _args: &[&str],
+ _event: PromptEvent,
+ ) -> anyhow::Result<()> {
+ let view = view!(cx.editor);
+ let doc_id = view.doc;
+ cx.editor.close_document(doc_id, false)?;
+ Ok(())
+ }
+
+ fn force_buffer_close(
+ cx: &mut compositor::Context,
+ _args: &[&str],
+ _event: PromptEvent,
+ ) -> anyhow::Result<()> {
+ let view = view!(cx.editor);
+ let doc_id = view.doc;
+ cx.editor.close_document(doc_id, true)?;
+ Ok(())
+ }
+
fn write_impl<P: AsRef<Path>>(
cx: &mut compositor::Context,
path: Option<P>,
@@ -1976,7 +1996,7 @@ mod cmd {
// close all views
let views: Vec<_> = cx.editor.tree.views().map(|(view, _)| view.id).collect();
for view_id in views {
- cx.editor.close(view_id, false);
+ cx.editor.close(view_id);
}
}
@@ -2020,7 +2040,7 @@ mod cmd {
// close all views
let views: Vec<_> = editor.tree.views().map(|(view, _)| view.id).collect();
for view_id in views {
- editor.close(view_id, false);
+ editor.close(view_id);
}
Ok(())
@@ -2333,6 +2353,20 @@ mod cmd {
completer: Some(completers::filename),
},
TypableCommand {
+ name: "buffer-close",
+ aliases: &["bc", "bclose"],
+ doc: "Close the current buffer.",
+ fun: buffer_close,
+ completer: None, // FIXME: buffer completer
+ },
+ TypableCommand {
+ name: "buffer-close!",
+ aliases: &["bc!", "bclose!"],
+ doc: "Close the current buffer forcefully (ignoring unsaved changes).",
+ fun: force_buffer_close,
+ completer: None, // FIXME: buffer completer
+ },
+ TypableCommand {
name: "write",
aliases: &["w"],
doc: "Write changes to disk. Accepts an optional path (:write some/path.txt)",
@@ -4914,7 +4948,7 @@ fn wclose(cx: &mut Context) {
}
let view_id = view!(cx.editor).id;
// close current split
- cx.editor.close(view_id, /* close_buffer */ false);
+ cx.editor.close(view_id);
}
fn wonly(cx: &mut Context) {
@@ -4926,7 +4960,7 @@ fn wonly(cx: &mut Context) {
.collect::<Vec<_>>();
for (view_id, focus) in views {
if !focus {
- cx.editor.close(view_id, /* close_buffer */ false);
+ cx.editor.close(view_id);
}
}
}