task: prompts[] fan-out, discourage lone tasks, stats #150
No files matched your search
@@ -20,6 +20,11 @@ impl Editor {
|
||||
pub fn insert(&mut self, s: &str) {
|
||||
// normalize pasted CRLF
|
||||
let s = s.replace("\r\n", "\n").replace('\r', "\n");
|
||||
// drop ESC etc. so pasted escape sequences cannot act on the terminal
|
||||
let s: String = s
|
||||
.chars()
|
||||
.filter(|c| !c.is_control() || matches!(c, '\n' | '\t'))
|
||||
.collect();
|
||||
self.buf.insert_str(self.cur, &s);
|
||||
self.cur += s.len();
|
||||
}
|
||||
@@ -278,3 +283,14 @@ mod tests {
|
||||
assert_eq!((e.buf.as_str(), e.cur), ("look at @src/main.rs ", 21));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod paste_tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn paste_multiline_keeps_text_and_strips_controls() {
|
||||
let mut e = Editor::default();
|
||||
e.insert("a\r\nb\x1b[31m\tc\x07");
|
||||
assert_eq!(e.buf, "a\nb[31m\tc");
|
||||
}
|
||||
}
|
||||
@@ -416,12 +416,15 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
|
||||
std::io::stdout(),
|
||||
crossterm::event::PopKeyboardEnhancementFlags
|
||||
);
|
||||
let _ = crossterm::execute!(std::io::stdout(), crossterm::event::DisableBracketedPaste);
|
||||
prev(i)
|
||||
}));
|
||||
}
|
||||
if mouse {
|
||||
let _ = crossterm::execute!(std::io::stdout(), crossterm::event::EnableMouseCapture);
|
||||
}
|
||||
// one Paste event per paste instead of a key event (and redraw) per char; newlines no longer submit
|
||||
let _ = crossterm::execute!(std::io::stdout(), crossterm::event::EnableBracketedPaste);
|
||||
let mut keys = EventStream::new();
|
||||
let mut tick = tokio::time::interval(std::time::Duration::from_millis(50));
|
||||
let mut lens_tick = tokio::time::interval(std::time::Duration::from_secs(2));
|
||||
@@ -485,7 +488,7 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
|
||||
}
|
||||
}
|
||||
TEvent::Mouse(m) => on_mouse(&mut app, m),
|
||||
TEvent::Paste(s) => app.ed.insert(&s),
|
||||
TEvent::Paste(s) if app.perm.is_none() && app.choose.is_none() && app.ask.is_none() => app.ed.insert(&s),
|
||||
TEvent::Resize(..) => app.sel = None,
|
||||
_ => {}
|
||||
}
|
||||
@@ -574,6 +577,7 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
|
||||
}
|
||||
}
|
||||
}
|
||||
let _ = crossterm::execute!(std::io::stdout(), crossterm::event::DisableBracketedPaste);
|
||||
if mouse {
|
||||
let _ = crossterm::execute!(std::io::stdout(), crossterm::event::DisableMouseCapture);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user