A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: fix crash on copying from codeblock
Abdullah Attae1339617b538
diff --git a/apps/web/src/utils/clipboard.ts b/apps/web/src/utils/clipboard.tsindex d369ce11e..f965ccedf 100644--- a/apps/web/src/utils/clipboard.ts+++ b/apps/web/src/utils/clipboard.ts@@ -26,10 +26,10 @@ const COPYABLE_FORMATS = ["text/html", "text/plain"] as const;export async function writeToClipboard(formats: Formats) {if ("ClipboardItem" in window) {const items: Record<string, Blob> = Object.fromEntries(- COPYABLE_FORMATS.map((f) => {+ COPYABLE_FORMATS.filter((f) => !!formats[f]).map((f) => {const content = formats[f];if (!content) return [];- return [f as string, textToBlob(content, f)] as const;+ return [f, textToBlob(content, f)] as const;}));return navigator.clipboard.write([new ClipboardItem(items)]);diff --git a/packages/editor/src/extensions/code-block/component.tsx b/packages/editor/src/extensions/code-block/component.tsxindex 8b86249d6..42c0051ca 100644--- a/packages/editor/src/extensions/code-block/component.tsx+++ b/packages/editor/src/extensions/code-block/component.tsx@@ -37,6 +37,7 @@ export function CodeblockComponent(const { language, indentLength, indentType, caretPosition } = node.attrs;// const [caretPosition, setCaretPosition] = useState<CaretPosition>();+ const elementRef = useRef<HTMLElement>();const [isOpen, setIsOpen] = useState(false);const toolbarRef = useRef<HTMLDivElement>(null);const theme = useThemeEngineStore((store) => store.theme);@@ -57,7 +58,10 @@ export function CodeblockComponent(}}><Text- ref={forwardRef}+ ref={(ref) => {+ elementRef.current = ref ?? undefined;+ forwardRef?.(ref);+ }}autoCorrect="off"autoCapitalize="none"css={theme.codeBlockCSS}@@ -163,7 +167,10 @@ export function CodeblockComponent(bg: "transparent"}}onClick={() => {- editor.storage.copyToClipboard?.(node.textContent);+ editor.storage.copyToClipboard?.(+ node.textContent,+ elementRef?.current?.innerHTML+ );start();}}title="Copy to clipboard"