Skip to content

Commit

Permalink
fix: don't trim the input text
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Dec 13, 2024
1 parent 737580b commit f2f74a9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
7 changes: 1 addition & 6 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ pub struct Cli {

impl Cli {
pub fn text(&self) -> Option<String> {
let text = self
.text
.iter()
.map(|x| x.trim().to_string())
.collect::<Vec<String>>()
.join(" ");
let text = self.text.to_vec().join(" ");
if text.is_empty() {
return None;
}
Expand Down
2 changes: 1 addition & 1 deletion src/config/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Input {
}
for (path, contents) in files {
texts.push(format!(
"============ PATH: {path} ============\n\n{contents}\n"
"============ PATH: {path} ============\n{contents}"
));
}
let (role, with_session, with_agent) = resolve_role(&config.read(), role);
Expand Down
16 changes: 12 additions & 4 deletions src/repl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl Repl {
Some(args) => match args.split_once(['\n', ' ']) {
Some((name, text)) => {
let role = self.config.read().retrieve_role(name.trim())?;
let input = Input::from_str(&self.config, text.trim(), Some(role));
let input = Input::from_str(&self.config, text, Some(role));
ask(&self.config, self.abort_signal.clone(), input, false).await?;
}
None => {
Expand Down Expand Up @@ -718,8 +718,9 @@ fn split_files_text(line: &str, is_win: bool) -> (Vec<String>, &str) {
word.to_string()
}
};
let chars: Vec<char> = line.chars().collect();

for (i, char) in line.chars().enumerate() {
for (i, char) in chars.iter().cloned().enumerate() {
match unbalance {
Some(ub_char) if ub_char == char => {
word.push(char);
Expand All @@ -730,12 +731,15 @@ fn split_files_text(line: &str, is_win: bool) -> (Vec<String>, &str) {
}
None => match char {
' ' | '\t' | '\r' | '\n' => {
if char == '\r' && chars.get(i + 1) == Some(&'\n') {
continue;
}
if let Some('\\') = prev_char.filter(|_| !is_win) {
word.push(char);
} else if !word.is_empty() {
if word == "--" {
word.clear();
text_starts_at = Some(i);
text_starts_at = Some(i + 1);
break;
}
words.push(unquote_word(&word));
Expand Down Expand Up @@ -763,7 +767,7 @@ fn split_files_text(line: &str, is_win: bool) -> (Vec<String>, &str) {
words.push(unquote_word(&word));
}
let text = match text_starts_at {
Some(start) => line[start..].trim(),
Some(start) => &line[start..],
None => "",
};

Expand Down Expand Up @@ -807,6 +811,10 @@ mod tests {
split_files_text("file.txt -- hello", false),
(vec!["file.txt".into()], "hello")
);
assert_eq!(
split_files_text("file.txt -- \thello", false),
(vec!["file.txt".into()], "\thello")
);
assert_eq!(
split_files_text("file.txt --\nhello", false),
(vec!["file.txt".into()], "hello")
Expand Down

0 comments on commit f2f74a9

Please sign in to comment.