Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: add support for pasting from vscode

thecodrr7dffcf015327
diff --git a/apps/web/package.json b/apps/web/package.json
index dd9f91dc3..7ee4611f4 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -12,7 +12,7 @@
"@notesnook/crypto": "^1.0.0",
"@notesnook/desktop": "file:desktop",
"@rebass/forms": "^4.0.6",
- "@streetwriters/tinymce-plugins": "^1.5.14",
+ "@streetwriters/tinymce-plugins": "^1.5.15",
"@tinymce/tinymce-react": "^3.13.0",
"async-mutex": "^0.3.2",
"axios": "^0.21.4",
diff --git a/apps/web/src/components/editor/tinymce.js b/apps/web/src/components/editor/tinymce.js
index 2d84c0fc0..eef678510 100644
--- a/apps/web/src/components/editor/tinymce.js
+++ b/apps/web/src/components/editor/tinymce.js
@@ -291,7 +291,12 @@ function TinyMCE(props) {
});
}
+ /**
+ *
+ * @param {ClipboardEvent} e
+ */
async function onPaste(e) {
+ if (handlePasteFromVSCode(e)) return;
if (e.clipboardData?.items?.length) {
for (let item of e.clipboardData.items) {
const file = item.getAsFile();
@@ -302,6 +307,30 @@ function TinyMCE(props) {
}
}
+ /**
+ *
+ * @param {ClipboardEvent} e
+ */
+ function handlePasteFromVSCode(e) {
+ let vscodeEditorData =
+ e.clipboardData.getData("vscode-editor-data");
+ if (!!vscodeEditorData?.trim()) {
+ const { mode } = JSON.parse(vscodeEditorData);
+ if (mode) {
+ e.preventDefault();
+
+ const code = e.clipboardData.getData("text/plain");
+ editor.execCommand("mceInsertCodeblock", false, {
+ code,
+ language: mode,
+ });
+
+ return true;
+ }
+ }
+ return false;
+ }
+
editor.on("ScrollIntoView", onScrollIntoView);
editor.on("tap", onTap);
editor.on(changeEvents, onEditorChange);