diff options
author | Joe Wilm <joe@jwilm.com> | 2016-09-27 08:27:39 -0700 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-09-27 08:27:39 -0700 |
commit | 7e69a070aaf92eff3bea1878bd77821b5ae60ede (patch) | |
tree | 3f023c347424abded1175cecfe3843094403c972 /src/input.rs | |
parent | 077a058cc428db8b1a9ec13f2a9c49ba500f7ac0 (diff) | |
download | alacritty-7e69a070aaf92eff3bea1878bd77821b5ae60ede.tar.gz alacritty-7e69a070aaf92eff3bea1878bd77821b5ae60ede.zip |
Don't write v when pasting on macOS
This is a bit of an experiment to see if simply handling 'v' in the
bindings will work or has any bugs not going through ReceivedCharacter.
The change is necessary though to prevent 'v' from being written in
front of every clipboard paste.
Diffstat (limited to 'src/input.rs')
-rw-r--r-- | src/input.rs | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/src/input.rs b/src/input.rs index 75df6d31..d0cbc600 100644 --- a/src/input.rs +++ b/src/input.rs @@ -85,6 +85,9 @@ pub enum Action { /// Paste contents of system clipboard Paste, + + /// Send a char to pty + Char(char) } /// Bindings for the LEFT key. @@ -198,10 +201,13 @@ static H_BINDINGS: &'static [Binding] = &[ #[cfg(target_os="macos")] static V_BINDINGS: &'static [Binding] = &[ Binding { mods: mods::SUPER, action: Action::Paste, mode: mode::ANY, notmode: mode::NONE }, + Binding { mods: mods::NONE, action: Action::Char('v'), mode: mode::ANY, notmode: mode::NONE }, ]; #[cfg(not(target_os="macos"))] -static V_BINDINGS: &'static [Binding] = &[]; +static V_BINDINGS: &'static [Binding] = &[ + Binding { mods: mods::NONE, action: Action::Char('v'), mode: mode::ANY, notmode: mode::NONE }, +]; #[cfg(target_os="linux")] static MOUSE_MIDDLE_BINDINGS: &'static [Binding] = &[ @@ -337,17 +343,31 @@ impl Processor { // TermMode negative if binding.notmode.is_empty() || !mode.intersects(binding.notmode) { // Modifier keys - if binding.mods.is_all() || mods.intersects(binding.mods) { + if binding.mods.is_all() || mods == binding.mods { // everything matches; run the binding action match binding.action { Action::Esc(s) => notifier.notify(s.as_bytes()), Action::Paste => { + println!("paste request"); let clip = ClipboardContext::new().expect("get clipboard"); clip.get_contents() - .map(|contents| notifier.notify(contents.into_bytes())) + .map(|contents| { + println!("got contents"); + notifier.notify(contents.into_bytes()) + }) .unwrap_or_else(|err| { err_println!("Error getting clipboard contents: {}", err); }); + + println!("ok"); + }, + Action::Char(c) => { + // TODO encode_utf8 returns an iterator with "as_slice" + // https://github.com/rust-lang/rust/issues/27784 has some + // discussion about this API changing to `write_utf8` which + // requires passing a &mut [u8] to be written into. + let encoded = c.encode_utf8(); + notifier.notify(encoded.as_slice().to_vec()); } } @@ -361,9 +381,13 @@ impl Processor { #[cfg(test)] mod tests { - use term::mode::{self, TermMode}; + use std::borrow::Cow; + use glutin::mods; + use term::mode; + + use super::Action; use super::Processor; use super::Binding; @@ -374,8 +398,8 @@ mod tests { } impl super::Notify for Receiver { - fn notify(&mut self, s: &str) { - self.got = Some(String::from(s)); + fn notify<B: Into<Cow<'static, [u8]>>>(&mut self, item: B) { + self.got = Some(String::from_utf8(item.into().to_vec()).unwrap()); } } @@ -455,4 +479,12 @@ mod tests { mode: mode::APP_CURSOR | mode::APP_KEYPAD, mods: mods::NONE } + + test_process_binding! { + name: process_binding_fail_with_extra_mods, + binding: Binding { mods: mods::SUPER, action: Action::Esc("arst"), mode: mode::ANY, notmode: mode::NONE }, + expect: None, + mode: mode::NONE, + mods: mods::SUPER | mods::ALT + } } |