8000 js: leave the clipboard to the page unless the canvas has the focus by benface · Pull Request #701 · not-fl3/miniquad · GitHub
[go: up one dir, main page]

Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions js/gl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1308,20 +1308,26 @@ var importObject = {
window. () {
resize(canvas, wasm_exports.resize);
};
// Only while the canvas has the focus, so a text field on the page
// keeps its own. Browsers can send these to the body or to the
// page's selection rather than the focused canvas.
window.addEventListener("copy", function (e) {
if (clipboard != null) {
event.clipboardData.setData('text/plain', clipboard);
event.preventDefault();
if (document.activeElement == canvas && clipboard != null) {
e.clipboardData.setData('text/plain', clipboard);
e.preventDefault();
}
});
window.addEventListener("cut", function (e) {
if (clipboard != null) {
event.clipboardData.setData('text/plain', clipboard);
event.preventDefault();
if (document.activeElement == canvas && clipboard != null) {
e.clipboardData.setData('text/plain', clipboard);
e.preventDefault();
}
});

window.addEventListener("paste", function (e) {
if (document.activeElement != canvas) {
return;
}
e.stopPropagation();
e.preventDefault();
var clipboardData = e.clipboardData || window.clipboardData;
Expand Down
Loading
0