mirror of
https://github.com/rmccorkl/TubeSage.git
synced 2026-07-22 06:45:31 +00:00
refactor: remove Copy template button (drops navigator.clipboard use)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b1282e8c6d
commit
d658ae21ef
1 changed files with 0 additions and 85 deletions
85
main.ts
85
main.ts
|
|
@ -6340,91 +6340,6 @@ class TemplateViewModal extends Modal {
|
|||
cls: 'tubesage-divider'
|
||||
});
|
||||
|
||||
// Create a container for the copy button
|
||||
const copyContainer = contentEl.createDiv({
|
||||
cls: ['tubesage-template-view-copy-container', 'tubesage-row-end']
|
||||
});
|
||||
|
||||
// Add copy text
|
||||
copyContainer.createSpan({
|
||||
text: 'Copy template',
|
||||
cls: 'tubesage-template-view-copy-text'
|
||||
});
|
||||
|
||||
// Copy icon button
|
||||
const copyButton = copyContainer.createEl('button', {
|
||||
cls: 'tubesage-icon-button' // Reuse existing class
|
||||
});
|
||||
|
||||
// Create an SVG for the copy icon
|
||||
const svgNamespace = "http://www.w3.org/2000/svg";
|
||||
const copySvg = activeDocument.createElementNS(svgNamespace, "svg");
|
||||
copySvg.setAttrs({
|
||||
viewBox: "0 0 24 24",
|
||||
width: "16",
|
||||
height: "16",
|
||||
stroke: "currentColor",
|
||||
fill: "none",
|
||||
'stroke-width': "2",
|
||||
'stroke-linecap': "round",
|
||||
'stroke-linejoin': "round"
|
||||
});
|
||||
|
||||
// Create the copy icon paths
|
||||
const copyRect = activeDocument.createElementNS(svgNamespace, "rect");
|
||||
copyRect.setAttrs({ x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" });
|
||||
copySvg.appendChild(copyRect);
|
||||
|
||||
const copyPath = activeDocument.createElementNS(svgNamespace, "path");
|
||||
copyPath.setAttr("d", "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1");
|
||||
copySvg.appendChild(copyPath);
|
||||
|
||||
// Add the SVG to the button
|
||||
copyButton.appendChild(copySvg);
|
||||
|
||||
// Add hover effect
|
||||
copyButton.addEventListener('mouseenter', () => {
|
||||
copyButton.addClass('tubesage-icon-button-hover'); // Reuse hover class logic
|
||||
});
|
||||
|
||||
copyButton.addEventListener('mouseleave', () => {
|
||||
copyButton.removeClass('tubesage-icon-button-hover'); // Reuse hover class logic
|
||||
});
|
||||
|
||||
// Make the text also clickable
|
||||
const copyTextElement = copyContainer.querySelector('span');
|
||||
|
||||
// Function to handle copy
|
||||
const handleCopy = () => {
|
||||
navigator.clipboard.writeText(templateContent)
|
||||
.then(() => {
|
||||
// Show success state
|
||||
if (copyTextElement) {
|
||||
const originalText = copyTextElement.textContent;
|
||||
copyTextElement.textContent = 'Copied';
|
||||
window.setTimeout(() => {
|
||||
copyTextElement.textContent = originalText;
|
||||
}, 2000);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('Failed to copy template:', err);
|
||||
// Show error state
|
||||
if (copyTextElement) {
|
||||
copyTextElement.textContent = 'Failed to copy';
|
||||
window.setTimeout(() => {
|
||||
copyTextElement.textContent = 'Copy template';
|
||||
}, 2000);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Add click handlers to both text and button
|
||||
copyButton.addEventListener('click', handleCopy);
|
||||
if (copyTextElement) {
|
||||
copyTextElement.addEventListener('click', handleCopy);
|
||||
}
|
||||
|
||||
// Display the content with syntax highlighting
|
||||
templateContainer.createEl('pre', {
|
||||
cls: 'language-markdown',
|
||||
|
|
|
|||
Loading…
Reference in a new issue