From 3dc5520a347a5e4be5d32c7eca17fab289ccae83 Mon Sep 17 00:00:00 2001 From: ath3 Date: Sun, 5 Dec 2021 22:52:43 +0100 Subject: [PATCH] Open files with spaces in filename --- helix-term/src/commands.rs | 40 +++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 3d583ba8a40da..8435943085725 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1989,8 +1989,10 @@ mod cmd { args: &[&str], _event: PromptEvent, ) -> anyhow::Result<()> { - let path = args.get(0).context("wrong argument count")?; - let _ = cx.editor.open(path.into(), Action::Replace)?; + ensure!(!args.is_empty(), "wrong argument count"); + for arg in args { + let _ = cx.editor.open(arg.into(), Action::Replace)?; + } Ok(()) } @@ -2980,7 +2982,39 @@ fn command_mode(cx: &mut Context) { // Handle typable commands if let Some(cmd) = cmd::TYPABLE_COMMAND_MAP.get(parts[0]) { - if let Err(e) = (cmd.fun)(cx, &parts[1..], event) { + let mut args: Vec<&str> = Vec::new(); + let quote_pos: Vec = input + .char_indices() + .filter(|&(_idx, char)| char == '"') + .map(|(idx, _char)| idx) + .collect(); + + if quote_pos.len() < 2 { + args = parts; + } else { + args.append( + &mut input[0..quote_pos[0]] + .split_whitespace() + .collect::>(), + ); + let mut quote_pos_iter = quote_pos.chunks(2).peekable(); + while let Some([i, j]) = quote_pos_iter.next() { + args.push(input[*i + 1..*j].trim()); + if let Some(next) = quote_pos_iter.peek() { + args.append( + &mut input[*j + 1..next[0]] + .split_whitespace() + .collect::>(), + ); + } + } + args.append( + &mut input[quote_pos[quote_pos.len() - 1] + 1..] + .split_whitespace() + .collect::>(), + ); + } + if let Err(e) = (cmd.fun)(cx, &args[1..], event) { cx.editor.set_error(format!("{}", e)); } } else {