Unexpected empty lines when copying-pasting #563
I looked into the issue and I found out when you copy from the memos using keyboard it added an extra line between lines, so what I did was manipulating the innerText when copying using crtl+c and removing the extra line added. looking forward to your feedback.
Uffizzi Preview deployment-22163 was deleted.
I think to listen Copy Event instead of the Ctrl+C Key-Down Event is a better way to fix the bug. Such as https://developer.mozilla.org/en-US/docs/Web/API/Element/copy_event WDYT?
I saw your commit, first used the paste event, and then changed it to the ctrl+c event. Why is this? Is there a reason I haven't thought of?
I think to listen Copy Event instead of the Ctrl+C Key-Down Event is a better way to fix the bug. Such as https://developer.mozilla.org/en-US/docs/Web/API/Element/copy_event WDYT?
I saw your commit, first used the paste event, and then changed it to the ctrl+c event. Why is this? Is there a reason I haven't thought of?
I tried to use the event listener, but because the text is being manipulated before rendering or other reasons that I might don’t know of, the event object only returns the first line "copied", I thought this might be something you know of
Uffizzi Preview deployment-22542 was deleted.
I think to listen Copy Event instead of the Ctrl+C Key-Down Event is a better way to fix the bug. Such as https://developer.mozilla.org/en-US/docs/Web/API/Element/copy_event WDYT? I saw your commit, first used the paste event, and then changed it to the ctrl+c event. Why is this? Is there a reason I haven't thought of?
I tried to use the event listener, but because the text is being manipulated before rendering or other reasons that I might don’t know of, the event object only returns the first line "copied", I thought this might be something you know of
I tried to achieve the same effect based on your idea.
// MemosList.tsx
import copy from "copy-to-clipboard";
...
useEffect(() => {
addEventListener("copy", handleCopy);
return () => {
removeEventListener("copy", handleCopy);
};
}, []);
const handleCopy = (event: ClipboardEvent) => {
event.preventDefault();
const rawStr = document.getSelection()?.toString();
if (rawStr !== undefined) {
copy(rawStr.split("\n\n").join("\n"));
}
};
...
The code works fine! This solution is based on yours, but covers more cases (like copy and ctrl+c). WDYT👀
I tried to simplify the code, I think it's equivalent. Please let me know if there is something I haven't thought of.