Unverified Commit e1c809d6 authored by CorrectRoadH's avatar CorrectRoadH Committed by GitHub

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

parent 218009a5
...@@ -8,6 +8,7 @@ import { DEFAULT_MEMO_LIMIT } from "@/helpers/consts"; ...@@ -8,6 +8,7 @@ import { DEFAULT_MEMO_LIMIT } from "@/helpers/consts";
import { checkShouldShowMemoWithFilters } from "@/helpers/filter"; import { checkShouldShowMemoWithFilters } from "@/helpers/filter";
import Memo from "./Memo"; import Memo from "./Memo";
import "@/less/memo-list.less"; import "@/less/memo-list.less";
import copy from "copy-to-clipboard";
const MemoList = () => { const MemoList = () => {
const { t } = useTranslation(); const { t } = useTranslation();
...@@ -148,6 +149,21 @@ const MemoList = () => { ...@@ -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 ( return (
<div className="memo-list-container"> <div className="memo-list-container">
{sortedMemos.map((memo) => ( {sortedMemos.map((memo) => (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment