mirror of
https://github.com/jldiaz/copy-protocol-plugin.git
synced 2026-07-22 06:56:55 +00:00
Fix validator errors and bump to 1.1.1
This commit is contained in:
parent
ff1688224a
commit
f31f9ed5eb
5 changed files with 36 additions and 23 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "copy-text-protocol",
|
||||
"name": "Copy Text Protocol",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Adds support for copying text to the clipboard using a custom protocol.",
|
||||
"author": "jldiaz",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "copy-text-protocol",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"description": "A plugin that adds support for copying text via a custom protocol.",
|
||||
"main": "main.js",
|
||||
"type": "module",
|
||||
|
|
|
|||
30
src/main.ts
30
src/main.ts
|
|
@ -9,25 +9,16 @@ import {
|
|||
} from '@codemirror/view';
|
||||
import { RangeSetBuilder } from '@codemirror/state';
|
||||
import { syntaxTree } from '@codemirror/language';
|
||||
import { SyntaxNodeRef } from '@lezer/common';
|
||||
|
||||
class CopyIconWidget extends WidgetType {
|
||||
constructor(private textToCopy: string) { super(); }
|
||||
|
||||
toDOM(): HTMLElement {
|
||||
const span = document.createElement('span');
|
||||
const span = activeDocument.createElement('span');
|
||||
span.className = 'copy-protocol-icon';
|
||||
span.style.cursor = 'copy';
|
||||
span.style.display = 'inline-flex';
|
||||
span.style.marginLeft = '5px';
|
||||
span.style.verticalAlign = 'middle';
|
||||
span.style.opacity = '0.8';
|
||||
|
||||
setIcon(span, 'copy');
|
||||
const svg = span.querySelector('svg');
|
||||
if (svg) {
|
||||
svg.style.width = '0.85em';
|
||||
svg.style.height = '0.85em';
|
||||
}
|
||||
|
||||
span.onclick = async (e) => {
|
||||
e.preventDefault();
|
||||
|
|
@ -35,16 +26,13 @@ class CopyIconWidget extends WidgetType {
|
|||
try {
|
||||
await navigator.clipboard.writeText(this.textToCopy);
|
||||
new Notice('Copied to clipboard!');
|
||||
span.style.transform = 'scale(1.2)';
|
||||
setTimeout(() => span.style.transform = 'scale(1)', 200);
|
||||
} catch (err) {
|
||||
span.addClass('is-clicked');
|
||||
window.setTimeout(() => span.removeClass('is-clicked'), 200);
|
||||
} catch {
|
||||
new Notice('Failed to copy.');
|
||||
}
|
||||
};
|
||||
|
||||
span.onmouseenter = () => span.style.opacity = '1';
|
||||
span.onmouseleave = () => span.style.opacity = '0.8';
|
||||
|
||||
return span;
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +61,7 @@ const copyLinkPlugin = ViewPlugin.fromClass(
|
|||
tree.iterate({
|
||||
from,
|
||||
to,
|
||||
enter(node: any) {
|
||||
enter(node: SyntaxNodeRef) {
|
||||
if (!node.name.includes('string_url')) return;
|
||||
const urlText = view.state.doc.sliceString(node.from, node.to);
|
||||
if (!urlText.includes('obsidian://copy')) return;
|
||||
|
|
@ -90,11 +78,11 @@ const copyLinkPlugin = ViewPlugin.fromClass(
|
|||
|
||||
if (!textToCopy) return;
|
||||
|
||||
let labelNode = null;
|
||||
let labelNode: SyntaxNodeRef | null = null;
|
||||
let curr = node.node.prevSibling;
|
||||
for (let i = 0; i < 6 && curr; i++) {
|
||||
if (curr.name.includes('link') && !curr.name.includes('formatting')) {
|
||||
labelNode = curr;
|
||||
labelNode = curr as unknown as SyntaxNodeRef;
|
||||
break;
|
||||
}
|
||||
curr = curr.prevSibling;
|
||||
|
|
@ -111,7 +99,7 @@ const copyLinkPlugin = ViewPlugin.fromClass(
|
|||
|
||||
if (!isEditing) {
|
||||
builder.add(labelNode.to, labelNode.to, Decoration.widget({
|
||||
widget: new CopyIconWidget(textToCopy as any),
|
||||
widget: new CopyIconWidget(textToCopy),
|
||||
side: 1
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
24
styles.css
24
styles.css
|
|
@ -48,3 +48,27 @@ a[href^="obsidian://copy"]:hover::after {
|
|||
a[href^="obsidian://copy"]:hover {
|
||||
cursor: copy !important;
|
||||
}
|
||||
|
||||
/* ── Widget Styles (Live Preview) ── */
|
||||
|
||||
.copy-protocol-icon {
|
||||
cursor: copy;
|
||||
display: inline-flex;
|
||||
margin-left: 5px;
|
||||
vertical-align: middle;
|
||||
opacity: 0.8;
|
||||
transition: transform 0.1s ease-out, opacity 0.1s ease-out;
|
||||
}
|
||||
|
||||
.copy-protocol-icon:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.copy-protocol-icon svg {
|
||||
width: 0.85em;
|
||||
height: 0.85em;
|
||||
}
|
||||
|
||||
.copy-protocol-icon.is-clicked {
|
||||
transform: scale(1.2);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"1.1.1": "0.15.0",
|
||||
"1.1.0": "0.15.0",
|
||||
"1.0.1": "0.15.0",
|
||||
"1.0.0": "0.15.0"
|
||||
|
|
|
|||
Loading…
Reference in a new issue