memos icon indicating copy to clipboard operation
memos copied to clipboard

Unexpected empty lines when copying-pasting #563

Open ameerturk96 opened this issue 2 years ago • 5 comments

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.

ameerturk96 avatar Apr 13 '23 16:04 ameerturk96

Uffizzi Preview deployment-22163 was deleted.

github-actions[bot] avatar Apr 13 '23 16:04 github-actions[bot]

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?

CorrectRoadH avatar Apr 14 '23 12:04 CorrectRoadH

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

ameerturk96 avatar Apr 17 '23 13:04 ameerturk96

Uffizzi Preview deployment-22542 was deleted.

github-actions[bot] avatar Apr 18 '23 05:04 github-actions[bot]

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.

CorrectRoadH avatar Apr 18 '23 05:04 CorrectRoadH