I have used
let copy = true;
export const textPaste = () => copy;
function myFunction() {
navigator.clipboard.writeText(copyText.value);
alert("Copied the text: " + copyText.value);
}
document.querySelector('#textBtn').addEventListener('click', myFunction);
to copy text from a text area to clipboard
But when I try to paste it onto my canvas the canvas doesn’t respond.
for pasting I used:
/* eslint-disable no-undef */
import { textPaste } from "./textHelper.js";
function textInput() {
this.icon = "./assets/textInput.png";
this.name = "textInput";
let drawing = false;
let startMouseX = -1;
let startMouseY = -1;
this.draw = function () {
if (mouseIsPressed) {
if (startMouseX === -1) {
startMouseX = mouseX;
startMouseY = mouseY;
drawing = true;
// save the current pixel Array
loadPixels();
if (mouseIsPressed) {
document.getElementById("myInput").value;
async function paste(input) {
const text = await navigator.clipboard.read();
input.value = text;
}
}
}
} else if (drawing) {
// save the pixels with the most recent rectangle and reset the
// drawing tool and start locations
const copy = textPaste();
set(startMouseX, startMouseY, copy);
loadPixels();
drawing = false;
startMouseX = -1;
startMouseY = -1;
}
};
}
export default textInput;