Skip to content

Commit

Permalink
Open files with spaces in filename
Browse files Browse the repository at this point in the history
  • Loading branch information
ath3 committed Dec 6, 2021
1 parent 461cd20 commit 3dc5520
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down Expand Up @@ -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<usize> = 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::<Vec<&str>>(),
);
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::<Vec<&str>>(),
);
}
}
args.append(
&mut input[quote_pos[quote_pos.len() - 1] + 1..]
.split_whitespace()
.collect::<Vec<&str>>(),
);
}
if let Err(e) = (cmd.fun)(cx, &args[1..], event) {
cx.editor.set_error(format!("{}", e));
}
} else {
Expand Down

0 comments on commit 3dc5520

Please sign in to comment.