Skip to content

Commit

Permalink
Suppress unnecessary clipboard errors
Browse files Browse the repository at this point in the history
  • Loading branch information
codefrau committed Jun 26, 2024
1 parent 52412f0 commit 2b9ce0c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 6 additions & 10 deletions squeak.js
Original file line number Diff line number Diff line change
Expand Up @@ -896,18 +896,14 @@ function createSqueakDisplay(canvas, options) {
// more copy/paste
if (navigator.clipboard) {
// new-style copy/paste (all modern browsers)
display.readFromSystemClipboard = () => navigator.clipboard.readText()
display.readFromSystemClipboard = () => display.handlingEvent &&
navigator.clipboard.readText()
.then(text => display.clipboardString = text)
.catch(err => {
if (!display.handlingEvent) console.warn("reading from clipboard outside event handler");
console.error("readFromSystemClipboard" + err.message);
});
display.writeToSystemClipboard = () => navigator.clipboard.writeText(display.clipboardString)
.catch(err => console.error("readFromSystemClipboard " + err.message));
display.writeToSystemClipboard = () => display.handlingEvent &&
navigator.clipboard.writeText(display.clipboardString)
.then(() => display.clipboardStringChanged = false)
.catch(err => {
if (!display.handlingEvent) console.warn("writing to clipboard outside event handler");
console.error("writeToSystemClipboard" + err.message);
});
.catch(err => console.error("writeToSystemClipboard " + err.message));
} else {
// old-style copy/paste
document.oncopy = function(evt, key) {
Expand Down
2 changes: 1 addition & 1 deletion vm.input.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Object.extend(Squeak.Primitives.prototype,
clipBoardPromise
.then(() => this.vm.popNandPush(1, this.makeStString(this.display.clipboardString)))
.catch(() => this.vm.popNandPush(1, this.vm.nilObj))
.finally(() => unfreeze());
.finally(unfreeze);
} else {
if (typeof(this.display.clipboardString) !== 'string') return false;
this.vm.popNandPush(1, this.makeStString(this.display.clipboardString));
Expand Down

0 comments on commit 2b9ce0c

Please sign in to comment.