Load the primary clipboard when pasting

Paste & PasteSelection are not quite the same. The former should be
pulling from the main clipboard where the latter does not.
This commit is contained in:
jc00ke 2017-01-19 21:55:38 -08:00 committed by Joe Wilm
parent 60d6071fb6
commit 9f064001e2
1 changed files with 20 additions and 11 deletions

View File

@ -156,25 +156,34 @@ impl Action {
} }
} }
}, },
Action::Paste | Action::Paste => {
Clipboard::new()
.and_then(|clipboard| clipboard.load_primary() )
.map(|contents| { self.paste(ctx, contents) })
.unwrap_or_else(|err| {
err_println!("Error loading data from clipboard. {}", Red(err));
});
},
Action::PasteSelection => { Action::PasteSelection => {
Clipboard::new() Clipboard::new()
.and_then(|clipboard| clipboard.load_selection()) .and_then(|clipboard| clipboard.load_selection() )
.map(|contents| { .map(|contents| { self.paste(ctx, contents) })
if ctx.terminal.mode().contains(mode::BRACKETED_PASTE) {
ctx.notifier.notify(&b"\x1b[200~"[..]);
ctx.notifier.notify(contents.into_bytes());
ctx.notifier.notify(&b"\x1b[201~"[..]);
} else {
ctx.notifier.notify(contents.into_bytes());
}
})
.unwrap_or_else(|err| { .unwrap_or_else(|err| {
warn!("Error loading data from clipboard. {}", Red(err)); warn!("Error loading data from clipboard. {}", Red(err));
}); });
}, },
} }
} }
fn paste<'a, N: Notify>(&self, ctx: &mut ActionContext<'a, N>, contents: String) {
if ctx.terminal.mode().contains(mode::BRACKETED_PASTE) {
ctx.notifier.notify(&b"\x1b[200~"[..]);
ctx.notifier.notify(contents.into_bytes());
ctx.notifier.notify(&b"\x1b[201~"[..]);
} else {
ctx.notifier.notify(contents.into_bytes());
}
}
} }
impl From<&'static str> for Action { impl From<&'static str> for Action {