Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable paste buffer to be changed before pasting #652

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ crossterm = { version = "0.27.0", features = ["serde"] }
fd-lock = "3.0.3"
itertools = "0.10.3"
nu-ansi-term = "0.49.0"
regex = "1.10.2"
rusqlite = { version = "0.29.0", optional = true }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0.79", optional = true }
Expand Down
26 changes: 23 additions & 3 deletions src/edit_mode/emacs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
PromptEditMode,
};
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
use regex::Regex;

/// Returns the current default emacs keybindings
pub fn default_emacs_keybindings() -> Keybindings {
Expand Down Expand Up @@ -160,9 +161,28 @@
Event::Resize(width, height) => ReedlineEvent::Resize(width, height),
Event::FocusGained => ReedlineEvent::None,
Event::FocusLost => ReedlineEvent::None,
Event::Paste(body) => ReedlineEvent::Edit(vec![EditCommand::InsertString(
body.replace("\r\n", "\n").replace('\r', "\n"),
)]),
Event::Paste(body) => {
let clean = body.replace("\r\n", "\n").replace('\r', "\n");
let posix_paste = true;
let posix_str = if posix_paste {

Check warning on line 167 in src/edit_mode/emacs.rs

View check run for this annotation

Codecov / codecov/patch

src/edit_mode/emacs.rs#L164-L167

Added lines #L164 - L167 were not covered by tests
// let env_vars =
// r"(?P<exp>^export )?(?P<envname>[A-Z-_0-9]+)=(?P<var>[A-Za-z0-9]+)";
let env_vars = r"(?P<envname>[A-Z-_0-9]+)=(?P<var>[A-Za-z0-9]+)";
let lines = r"(?m)(?P<lines> \\$)";
let re = Regex::new(env_vars).unwrap();
// .replace_all(&clean, "$$env.$envname = $var")
let clean_env = re
.replace_all(&clean, "$$env.$envname = $var")
.to_string()
.replace("export", "");
let re = Regex::new(lines).unwrap();
let clean_lines = re.replace_all(&clean_env, "").to_string();
clean_lines

Check warning on line 180 in src/edit_mode/emacs.rs

View check run for this annotation

Codecov / codecov/patch

src/edit_mode/emacs.rs#L170-L180

Added lines #L170 - L180 were not covered by tests
} else {
clean

Check warning on line 182 in src/edit_mode/emacs.rs

View check run for this annotation

Codecov / codecov/patch

src/edit_mode/emacs.rs#L182

Added line #L182 was not covered by tests
};
ReedlineEvent::Edit(vec![EditCommand::InsertString(posix_str)])

Check warning on line 184 in src/edit_mode/emacs.rs

View check run for this annotation

Codecov / codecov/patch

src/edit_mode/emacs.rs#L184

Added line #L184 was not covered by tests
}
}
}

Expand Down