Skip to content

Commit

Permalink
Fix copy/cut/paste
Browse files Browse the repository at this point in the history
  • Loading branch information
codefrau committed Mar 11, 2024
1 parent 978df7b commit 6a9a247
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions squeak.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,17 +814,19 @@ function createSqueakDisplay(canvas, options) {
return evt.preventDefault();
}
// copy/paste new-style
if (navigator.clipboard && (display.isMac ? evt.metaKey : evt.ctrlKey)) {
if (display.isMac ? evt.metaKey : evt.ctrlKey) {
switch (evt.key) {
case "c":
case "x":
if (!navigator.clipboard?.writeText) return; // fire document.oncopy/oncut
var text = display.executeClipboardCopy(evt.key, evt.timeStamp);
if (typeof text === 'string') {
navigator.clipboard.writeText(text)
.catch(function(err) { console.error("display: copy error " + err.message); });
}
return evt.preventDefault();
case "v":
if (!navigator.clipboard?.readText) return; // fire document.onpaste
navigator.clipboard.readText()
.then(function(text) {
display.executeClipboardPaste(text, evt.timeStamp);
Expand All @@ -846,7 +848,7 @@ function createSqueakDisplay(canvas, options) {
recordModifiers(evt, display);
};
// copy/paste old-style
if (!navigator.clipboard) {
if (!navigator.clipboard?.writeText) {
document.oncopy = function(evt, key) {
var text = display.executeClipboardCopy(key, evt.timeStamp);
if (typeof text === 'string') {
Expand All @@ -858,6 +860,8 @@ function createSqueakDisplay(canvas, options) {
if (!display.vm) return true;
document.oncopy(evt, 'x');
};
}
if (!navigator.clipboard?.readText) {
document.onpaste = function(evt) {
var text = evt.clipboardData.getData('Text');
display.executeClipboardPaste(text, evt.timeStamp);
Expand Down
2 changes: 1 addition & 1 deletion vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Object.extend(Squeak,
"version", {
// system attributes
vmVersion: "SqueakJS 1.1.2",
vmDate: "2024-03-03", // Maybe replace at build time?
vmDate: "2024-03-10", // Maybe replace at build time?
vmBuild: "unknown", // or replace at runtime by last-modified?
vmPath: "unknown", // Replace at runtime
vmFile: "vm.js",
Expand Down

0 comments on commit 6a9a247

Please sign in to comment.