Fix some things

main
Isaiah Odhner 2019-09-17 17:28:30 -04:00
parent 09ff712a5f
commit 96ea75569e
2 changed files with 20 additions and 14 deletions

View File

@ -353,13 +353,7 @@ $G.on("cut copy paste", function(e){
if(e.type === "copy" || e.type === "cut"){
if(selection && selection.canvas){
try {
if (e.type === "cut") {
edit_cut();
} else {
edit_copy();
}
} catch(e) {
var do_sync_clipboard_copy_or_cut = function() {
if(window.require && window.process){
// TODO: remove special electron handling for clipboard stuff if I can upgrade to a version that supports the async clipboard API with images
const {clipboard, nativeImage} = require('electron');
@ -384,6 +378,18 @@ $G.on("cut copy paste", function(e){
if(e.type === "cut"){
delete_selection();
}
};
if (!navigator.clipboard) {
return do_sync_clipboard_copy_or_cut();
}
try {
if (e.type === "cut") {
edit_cut();
} else {
edit_copy();
}
} catch(e) {
do_sync_clipboard_copy_or_cut();
}
}
}else if(e.type === "paste"){

View File

@ -96,11 +96,11 @@ function get_URIs(text) {
// parse URLs, discarding anything that parses as a relative URL
var uris = [];
for (var i=0; i<lines.length; i++) {
// TODO: handle errors?
var url = new URL(lines[i], "https://relative-urls-are-invalid.example.com"); // TODO: is this necessary? I assumed it would use the current page URL by default as a base
if (-1 === url.host.indexOf("relative-urls-are-invalid.example.com")) {
try {
var url = new URL(lines[i]);
uris.push(url.href);
}
// eslint-disable-next-line no-empty
} catch(e) {}
}
return uris;
}
@ -654,7 +654,7 @@ async function edit_copy(execCommandFallback){
return;
}
if (!navigator.clipboard) {
show_error_message("The Async Clipboard API not supported by this browser. " + browserRecommendationForClipboardAccess);
show_error_message("The Async Clipboard API is not supported by this browser. " + browserRecommendationForClipboardAccess);
}
// TODO: handle copying text (textarea or otherwise) w/ navigator.clipboard.writeText
@ -688,7 +688,7 @@ function edit_cut(execCommandFallback){
return;
}
if (!navigator.clipboard) {
show_error_message("The Async Clipboard API not supported by this browser. " + browserRecommendationForClipboardAccess);
show_error_message("The Async Clipboard API is not supported by this browser. " + browserRecommendationForClipboardAccess);
}
edit_copy();
delete_selection();
@ -708,7 +708,7 @@ async function edit_paste(execCommandFallback){
return;
}
if (!navigator.clipboard) {
show_error_message("The Async Clipboard API not supported by this browser. " + browserRecommendationForClipboardAccess);
show_error_message("The Async Clipboard API is not supported by this browser. " + browserRecommendationForClipboardAccess);
}
try {
const clipboardItems = await navigator.clipboard.read();