commit 1e87f9d95d0f2eef63e070836135b473bf083410
parent c1913e4fa58ed7b7efae17958903e18f607af74c
Author: Hunter
Date:   Wed, 14 Jan 2026 11:48:14 -0500

add click-to-select for stock image table rows

Diffstat:
Mmain.js | 30++++++++++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/main.js b/main.js @@ -45,9 +45,9 @@ function expandImagesTag(html) { const images = Array.from(stockImages.values()).sort(); if (images.length === 0) return '<p>No images available</p>'; const rows = images.map(filename => - `<tr><td>${filename}</td><td style="text-align:center;"><img src="images/${filename}" style="max-width:100%;height:auto;"></td></tr>` + `<tr class="stock-image-row" data-filename="${filename}" style="cursor:pointer;"><td>${filename}</td><td style="text-align:center;"><img src="images/${filename}" style="max-width:100%;height:auto;"></td></tr>` ).join(''); - return `<table border="1" cellpadding="8" cellspacing="0" style="max-width:100%;box-sizing:border-box;table-layout:fixed;"><colgroup><col style="width:50%"><col style="width:50%"></colgroup>${rows}</table>`; + return `<table class="stock-image-table" border="1" cellpadding="8" cellspacing="0" style="max-width:100%;box-sizing:border-box;table-layout:fixed;"><colgroup><col style="width:50%"><col style="width:50%"></colgroup>${rows}</table>`; }); } const editorPane = document.querySelector('.editor-pane'); @@ -203,6 +203,32 @@ function updatePreview() { doc.body.appendChild(button); } + // Add click handlers for stock image table rows + const stockImageRows = doc.querySelectorAll('.stock-image-row'); + stockImageRows.forEach(row => { + row.addEventListener('click', () => { + const filename = row.getAttribute('data-filename'); + if (!filename) return; + + // Find and replace <img src="?"> in the editor + const editorContent = editorView.state.doc.toString(); + const imgPattern = /<img\s+src\s*=\s*["']?\?["']?\s*\/?>/i; + const match = editorContent.match(imgPattern); + + if (match) { + const start = editorContent.indexOf(match[0]); + const end = start + match[0].length; + const replacement = `<img src="${filename}">`; + + editorView.dispatch({ + changes: { from: start, to: end, insert: replacement } + }); + saveToStorage(); + updatePreview(); + } + }); + }); + // Restore scroll position setTimeout(() => { try {