fix: unexpected empty lines when copying-pasting (#1654)

This commit is contained in:
CorrectRoadH 2023-05-13 22:08:54 +08:00 committed by GitHub
parent 218009a5ec
commit e1c809d6f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,7 @@ import { DEFAULT_MEMO_LIMIT } from "@/helpers/consts";
import { checkShouldShowMemoWithFilters } from "@/helpers/filter";
import Memo from "./Memo";
import "@/less/memo-list.less";
import copy from "copy-to-clipboard";
const MemoList = () => {
const { t } = useTranslation();
@ -148,6 +149,21 @@ const MemoList = () => {
}
};
useEffect(() => {
window.addEventListener("copy", handleCopy);
return () => {
window.removeEventListener("copy", handleCopy);
};
}, []);
const handleCopy = (event: ClipboardEvent) => {
event.preventDefault();
const rawStr = document.getSelection()?.toString();
if (rawStr !== undefined) {
copy(rawStr.split("\n\n").join("\n"));
}
};
return (
<div className="memo-list-container">
{sortedMemos.map((memo) => (