From 88304b90a495152f10432c27a044981a71e4c199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Mon, 1 Jun 2026 16:28:51 +0200 Subject: [PATCH] Update node content if only pasting a file --- static/js/page_node.mjs | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/static/js/page_node.mjs b/static/js/page_node.mjs index 86c29c0..fc050d4 100644 --- a/static/js/page_node.mjs +++ b/static/js/page_node.mjs @@ -1,4 +1,4 @@ -import { ROOT_NODE, uuidv7, StoreFile } from 'node_store' +import { ROOT_NODE, uuidv7 } from 'node_store' import { CustomHTMLElement } from './lib/custom_html_element.mjs' import { MarkedPosition } from './marked_position.mjs' @@ -119,7 +119,7 @@ export class N2PageNodeUI extends CustomHTMLElement { return this.classList.contains('show-markdown') } }// }}} - async pasteHandler(event) { + async pasteHandler(event) {// {{{ const clipboardItems = event.clipboardData?.items if (!clipboardItems) return @@ -139,27 +139,16 @@ export class N2PageNodeUI extends CustomHTMLElement { const [start, end] = [this.elNodeContent.selectionStart, this.elNodeContent.selectionEnd] this.elNodeContent.setRangeText(`![${file.name}](db://${uuid})`, start, end, 'select'); + // Editing the textarea programatically doesn't generate the events it usually gets when edited interactively. + this.node.setContent(this.elNodeContent.value) + break default: alert(`Unknown paste type of '${item.kind}'`) } } - } - - // Example usage: Displaying the image or preparing it for upload - handleImageBlob(blob) { - // 1. Create a local URL to preview it in an tag if needed - const localUrl = URL.createObjectURL(blob) - console.log('Local preview URL:', localUrl) - - // 2. Or prepare it for a FormData upload - const formData = new FormData() - formData.append('image', blob, 'pasted-image.png') - - // fetch('/upload', { method: 'POST', body: formData }) - } - + }// }}} editMarkdown(data) {// {{{ this.showMarkdown(false) this.elNodeContent.selectionStart = data.position.start