mirror of https://github.com/helix-editor/helix
Add an `--insensitive`/`-i` flag for `:sort` (#13560)
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>pull/11441/head
parent
cb1ec1b27e
commit
223ceec10a
|
@ -2107,10 +2107,6 @@ fn sort(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyhow:
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
sort_impl(cx, args.has_flag("reverse"))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sort_impl(cx: &mut compositor::Context, reverse: bool) -> anyhow::Result<()> {
|
|
||||||
let scrolloff = cx.editor.config().scrolloff;
|
let scrolloff = cx.editor.config().scrolloff;
|
||||||
let (view, doc) = current!(cx.editor);
|
let (view, doc) = current!(cx.editor);
|
||||||
let text = doc.text().slice(..);
|
let text = doc.text().slice(..);
|
||||||
|
@ -2126,10 +2122,14 @@ fn sort_impl(cx: &mut compositor::Context, reverse: bool) -> anyhow::Result<()>
|
||||||
.map(|fragment| fragment.chunks().collect())
|
.map(|fragment| fragment.chunks().collect())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
fragments.sort_by(match reverse {
|
fragments.sort_by(
|
||||||
true => |a: &Tendril, b: &Tendril| b.cmp(a),
|
match (args.has_flag("insensitive"), args.has_flag("reverse")) {
|
||||||
false => |a: &Tendril, b: &Tendril| a.cmp(b),
|
(true, true) => |a: &Tendril, b: &Tendril| b.to_lowercase().cmp(&a.to_lowercase()),
|
||||||
});
|
(true, false) => |a: &Tendril, b: &Tendril| a.to_lowercase().cmp(&b.to_lowercase()),
|
||||||
|
(false, true) => |a: &Tendril, b: &Tendril| b.cmp(a),
|
||||||
|
(false, false) => |a: &Tendril, b: &Tendril| a.cmp(b),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
let transaction = Transaction::change(
|
let transaction = Transaction::change(
|
||||||
doc.text(),
|
doc.text(),
|
||||||
|
@ -3357,6 +3357,12 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
|
||||||
signature: Signature {
|
signature: Signature {
|
||||||
positionals: (0, Some(0)),
|
positionals: (0, Some(0)),
|
||||||
flags: &[
|
flags: &[
|
||||||
|
Flag {
|
||||||
|
name: "insensitive",
|
||||||
|
alias: Some('i'),
|
||||||
|
doc: "sort the ranges case-insensitively",
|
||||||
|
..Flag::DEFAULT
|
||||||
|
},
|
||||||
Flag {
|
Flag {
|
||||||
name: "reverse",
|
name: "reverse",
|
||||||
alias: Some('r'),
|
alias: Some('r'),
|
||||||
|
|
Loading…
Reference in New Issue