Comments (4)
What operating system are you on?
When trying to reproduce behavior on Windows I get asdf,\nasdf
not asdf,nasdf
.
I also grepped for Ah, found it. ShellWords
and nothing came up. What module would this be in?Shellwords
, not ShellWords
.
from helix.
Made a pretty naive implimentation to escape given sequences. Seems to work fine? I added other a few other common patterns that might crop up for light testing. Not sure if something like this already exists as a helper function somewhere, so just hacked this one together.
fn yank_joined_impl(editor: &mut Editor, separator: &str, register: char) {
let (view, doc) = current!(editor);
let text = doc.text().slice(..);
let selection = doc.selection(view.id);
let selections = selection.len();
let joined = selection
.fragments(text)
.fold(String::new(), |mut acc, fragment| {
if !acc.is_empty() {
- acc.push_str(separator);
+ acc.push_str(&escape(separator));
}
acc.push_str(&fragment);
acc
});
match editor.registers.write(register, vec![joined]) {
Ok(_) => editor.set_status(format!(
"joined and yanked {selections} selection{} to register {register}",
if selections == 1 { "" } else { "s" }
)),
Err(err) => editor.set_error(err.to_string()),
}
}
fn escape(separator: &str) -> Cow<'_, str> {
enum State {
Normal,
Escape,
}
let mut escaped = String::new();
let mut state = State::Normal;
let mut is_escaped = false;
for (idx, ch) in separator.char_indices() {
match state {
State::Normal => match ch {
'\\' => {
if !is_escaped {
// PERF: As not every separator will be escaped, we use `String::new` as that has no initial
// allocation. If an escape is found, then we reserve capacity thats the len of the separator
// as the new escaped string will be at least that long.
escaped.reserve(separator.len());
if idx > 0 {
// First time finding an escape, so all prior chars can be added to the new escaped version
// if its not the very first char found.
escaped.push_str(&separator[0..idx]);
}
}
state = State::Escape;
is_escaped = true;
}
_ => {
if is_escaped {
escaped.push(ch);
}
}
},
State::Escape => match ch {
'n' => {
escaped.push('\n');
state = State::Normal;
}
't' => {
escaped.push('\t');
state = State::Normal;
}
'r' => {
escaped.push('\r');
state = State::Normal;
}
'\\' => {
escaped.push('\\');
state = State::Normal;
}
_ => {
escaped.push('\\');
escaped.push(ch);
state = State::Normal;
}
},
}
}
if is_escaped {
escaped.into()
} else {
separator.into()
}
}
from helix.
Ah, interesting. I work with a remote setup with helix running in tmux on Ubuntu, but SSHd from MacOS with Alacritty. Thanks for the code, I'll give it a shot and see what I can come up with!
from helix.
This kind of escaping can expand further than just newlines. Currently you cannot paste in unicode, like 🤩, in the yank-joined command buffer. But by offering a way to escape the literal \u{1f929}
then you could join with this emoji even if you can't paste it in. Tabs would be another one. Can't tab in the command buffer. You could even add spaces with \u{20}
, something that has no meaning currently as it gets ignored.
If you don't mind, I'll try opening up a pr that would provide a way to unescape these things in general, and then use it to unescape the separator.
from helix.
Related Issues (20)
- Add option to disable sorting for file picker
- (config help) Swap the "<space>f" and <space>F" bindings HOT 3
- Using :w as shortcut in insert mode leaves buffer with unsaved marker
- Using `diff` in gutters twice makes Helix get stuck
- swapping the space (f and F) keys, provide unexpected behavior.
- Formatting issues from tutor
- Helix is slow in SSHFS HOT 2
- Show current workspace with working directory in status line
- Syntax Highlighting for Rust Macros
- Unintuitive line movements with relative line numbers
- Remap scrolls HOT 1
- Combine status line with command line HOT 1
- Dynamically determine config value HOT 1
- Enable OSC52 automatically if connected via SSH HOT 1
- Race condition when typing before symbol picker opens HOT 1
- Separate `:rename` command that moves within the current directory
- Allow remapping of dot HOT 1
- commands with international keyboard
- Error in languages.toml
- Rust Method Chain Indentation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from helix.