Merge pull request #1061 from glacambre/errormsg_on_failed_xselection

excmds.ts: Display error messages when setclip/getclip fails
This commit is contained in:
Oliver Blanthorn 2018-10-05 10:32:05 +01:00 committed by GitHub
commit 6ef16cc03b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2696,7 +2696,13 @@ export async function yank(...content: string[]) {
//#background_helper
async function setclip(str) {
// Functions to avoid retyping everything everywhere
let s = () => Native.clipboard("set", str)
// Note: We're using fillcmdline here because exceptions are somehow not caught. We're rethrowing because otherwise the error message will be overwritten with the "yank successful" message.
let s = () => Native.clipboard("set", str).catch(e => {
let msg = "# Failed to set X selection. Is the native messenger installed and is it >=v.0.1.7?"
fillcmdline(msg)
throw msg
})
let c = async () => {
await messageActiveTab("commandline_content", "focus")
await messageActiveTab("commandline_frame", "setClipboard", [str])
@ -2727,7 +2733,11 @@ async function getclip() {
if ((await config.getAsync("putfrom")) == "clipboard") {
return messageActiveTab("commandline_frame", "getClipboard")
} else {
return Native.clipboard("get", "")
return Native.clipboard("get", "").catch(e => {
let msg = "# Failed to get X selection. Is the native messenger installed?"
fillcmdline(msg)
throw msg
})
}
}