This commit is contained in:
2026-01-29 23:49:03 +01:00
parent d8fcd65286
commit 5694b726f8
2 changed files with 24 additions and 13 deletions

View File

@@ -1 +1 @@
1.1.57 1.1.58

View File

@@ -918,28 +918,39 @@
linkApply.addEventListener('click', () => { linkApply.addEventListener('click', () => {
const url = String(linkInput.value || '').trim(); const url = String(linkInput.value || '').trim();
if (!url) { if (!url) {
exec('unlink'); linkRemove.click();
hideLinkPanel();
return; return;
} }
try { try {
const linkEl = findLinkAtSelection(); const linkEl = findLinkAtSelection();
if (linkEl) { if (linkEl && linkEl.setAttribute) {
const docRef = content.ownerDocument || document; linkEl.setAttribute('href', url);
const sel = docRef.getSelection(); hideLinkPanel();
if (sel && docRef.createRange) { return;
const range = docRef.createRange();
range.selectNodeContents(linkEl);
sel.removeAllRanges();
sel.addRange(range);
saveSelection();
}
} }
} catch {} } catch {}
const range = getSelectionRange();
if (!range || range.collapsed) {
hideLinkPanel();
return;
}
restoreSelection();
exec('createLink', url); exec('createLink', url);
hideLinkPanel(); hideLinkPanel();
}); });
linkRemove.addEventListener('click', () => { linkRemove.addEventListener('click', () => {
try {
const linkEl = findLinkAtSelection();
if (linkEl && linkEl.parentNode) {
while (linkEl.firstChild) {
linkEl.parentNode.insertBefore(linkEl.firstChild, linkEl);
}
linkEl.parentNode.removeChild(linkEl);
hideLinkPanel();
return;
}
} catch {}
restoreSelection();
exec('unlink'); exec('unlink');
hideLinkPanel(); hideLinkPanel();
}); });