mirror of https://github.com/helix-editor/helix
Merge 5328149c52
into 362e97e927
commit
463c19f8d4
|
@ -7,6 +7,10 @@
|
||||||
| `:buffer-close!`, `:bc!`, `:bclose!` | Close the current buffer forcefully, ignoring unsaved changes. |
|
| `:buffer-close!`, `:bc!`, `:bclose!` | Close the current buffer forcefully, ignoring unsaved changes. |
|
||||||
| `:buffer-close-others`, `:bco`, `:bcloseother` | Close all buffers but the currently focused one. |
|
| `:buffer-close-others`, `:bco`, `:bcloseother` | Close all buffers but the currently focused one. |
|
||||||
| `:buffer-close-others!`, `:bco!`, `:bcloseother!` | Force close all buffers but the currently focused one. |
|
| `:buffer-close-others!`, `:bco!`, `:bcloseother!` | Force close all buffers but the currently focused one. |
|
||||||
|
| `:buffer-close-left`, `:bcl`, `:bcloseleft` | Close all buffers to the left of the currently focused one. |
|
||||||
|
| `:buffer-close-left!`, `:bcl!`, `:bcloseleft!` | Force close all buffers to the left of the currently focused one. |
|
||||||
|
| `:buffer-close-right`, `:bcr`, `:bcloseright` | Close all buffers to the right of the currently focused one. |
|
||||||
|
| `:buffer-close-right!`, `:bcr!`, `:bcloseright!` | Force close all buffers to the right of the currently focused one. |
|
||||||
| `:buffer-close-all`, `:bca`, `:bcloseall` | Close all buffers without quitting. |
|
| `:buffer-close-all`, `:bca`, `:bcloseall` | Close all buffers without quitting. |
|
||||||
| `:buffer-close-all!`, `:bca!`, `:bcloseall!` | Force close all buffers ignoring unsaved changes without quitting. |
|
| `:buffer-close-all!`, `:bca!`, `:bcloseall!` | Force close all buffers ignoring unsaved changes without quitting. |
|
||||||
| `:buffer-next`, `:bn`, `:bnext` | Goto next buffer. |
|
| `:buffer-next`, `:bn`, `:bnext` | Goto next buffer. |
|
||||||
|
|
|
@ -230,13 +230,79 @@ fn force_buffer_close(
|
||||||
buffer_close_by_ids_impl(cx, &document_ids, true)
|
buffer_close_by_ids_impl(cx, &document_ids, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn buffer_gather_others_impl(editor: &mut Editor) -> Vec<DocumentId> {
|
enum OtherBuffers {
|
||||||
|
All,
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn buffer_gather_others_impl(editor: &mut Editor, sel: OtherBuffers) -> Vec<DocumentId> {
|
||||||
let current_document = &doc!(editor).id();
|
let current_document = &doc!(editor).id();
|
||||||
editor
|
|
||||||
.documents()
|
let ids = editor.documents().map(|doc| doc.id());
|
||||||
.map(|doc| doc.id())
|
|
||||||
.filter(|doc_id| doc_id != current_document)
|
match sel {
|
||||||
.collect()
|
OtherBuffers::All => ids.filter(|doc_id| doc_id != current_document).collect(),
|
||||||
|
OtherBuffers::Left => ids
|
||||||
|
.take_while(|doc_id| doc_id != current_document)
|
||||||
|
.collect(),
|
||||||
|
OtherBuffers::Right => ids
|
||||||
|
.skip_while(|doc_id| doc_id != current_document)
|
||||||
|
.skip(1)
|
||||||
|
.collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn buffer_close_right(
|
||||||
|
cx: &mut compositor::Context,
|
||||||
|
_args: Args,
|
||||||
|
event: PromptEvent,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
if event != PromptEvent::Validate {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let document_ids = buffer_gather_others_impl(cx.editor, OtherBuffers::Right);
|
||||||
|
buffer_close_by_ids_impl(cx, &document_ids, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn force_buffer_close_right(
|
||||||
|
cx: &mut compositor::Context,
|
||||||
|
_args: Args,
|
||||||
|
event: PromptEvent,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
if event != PromptEvent::Validate {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let document_ids = buffer_gather_others_impl(cx.editor, OtherBuffers::Right);
|
||||||
|
buffer_close_by_ids_impl(cx, &document_ids, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn buffer_close_left(
|
||||||
|
cx: &mut compositor::Context,
|
||||||
|
_args: Args,
|
||||||
|
event: PromptEvent,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
if event != PromptEvent::Validate {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let document_ids = buffer_gather_others_impl(cx.editor, OtherBuffers::Left);
|
||||||
|
buffer_close_by_ids_impl(cx, &document_ids, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn force_buffer_close_left(
|
||||||
|
cx: &mut compositor::Context,
|
||||||
|
_args: Args,
|
||||||
|
event: PromptEvent,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
if event != PromptEvent::Validate {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let document_ids = buffer_gather_others_impl(cx.editor, OtherBuffers::Left);
|
||||||
|
buffer_close_by_ids_impl(cx, &document_ids, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn buffer_close_others(
|
fn buffer_close_others(
|
||||||
|
@ -248,7 +314,7 @@ fn buffer_close_others(
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let document_ids = buffer_gather_others_impl(cx.editor);
|
let document_ids = buffer_gather_others_impl(cx.editor, OtherBuffers::All);
|
||||||
buffer_close_by_ids_impl(cx, &document_ids, false)
|
buffer_close_by_ids_impl(cx, &document_ids, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +327,7 @@ fn force_buffer_close_others(
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let document_ids = buffer_gather_others_impl(cx.editor);
|
let document_ids = buffer_gather_others_impl(cx.editor, OtherBuffers::All);
|
||||||
buffer_close_by_ids_impl(cx, &document_ids, true)
|
buffer_close_by_ids_impl(cx, &document_ids, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2659,6 +2725,50 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
|
||||||
..Signature::DEFAULT
|
..Signature::DEFAULT
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
TypableCommand {
|
||||||
|
name: "buffer-close-left",
|
||||||
|
aliases: &["bcl", "bcloseleft"],
|
||||||
|
doc: "Close all buffers to the left of the currently focused one.",
|
||||||
|
fun: buffer_close_left,
|
||||||
|
completer: CommandCompleter::none(),
|
||||||
|
signature: Signature {
|
||||||
|
positionals: (0, Some(0)),
|
||||||
|
..Signature::DEFAULT
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TypableCommand {
|
||||||
|
name: "buffer-close-left!",
|
||||||
|
aliases: &["bcl!", "bcloseleft!"],
|
||||||
|
doc: "Force close all buffers to the left of the currently focused one.",
|
||||||
|
fun: force_buffer_close_left,
|
||||||
|
completer: CommandCompleter::none(),
|
||||||
|
signature: Signature {
|
||||||
|
positionals: (0, Some(0)),
|
||||||
|
..Signature::DEFAULT
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TypableCommand {
|
||||||
|
name: "buffer-close-right",
|
||||||
|
aliases: &["bcr", "bcloseright"],
|
||||||
|
doc: "Close all buffers to the right of the currently focused one.",
|
||||||
|
fun: buffer_close_right,
|
||||||
|
completer: CommandCompleter::none(),
|
||||||
|
signature: Signature {
|
||||||
|
positionals: (0, Some(0)),
|
||||||
|
..Signature::DEFAULT
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TypableCommand {
|
||||||
|
name: "buffer-close-right!",
|
||||||
|
aliases: &["bcr!", "bcloseright!"],
|
||||||
|
doc: "Force close all buffers to the right of the currently focused one.",
|
||||||
|
fun: force_buffer_close_right,
|
||||||
|
completer: CommandCompleter::none(),
|
||||||
|
signature: Signature {
|
||||||
|
positionals: (0, Some(0)),
|
||||||
|
..Signature::DEFAULT
|
||||||
|
},
|
||||||
|
},
|
||||||
TypableCommand {
|
TypableCommand {
|
||||||
name: "buffer-close-all",
|
name: "buffer-close-all",
|
||||||
aliases: &["bca", "bcloseall"],
|
aliases: &["bca", "bcloseall"],
|
||||||
|
|
Loading…
Reference in New Issue