mirror of
https://github.com/zadam/trilium.git
synced 2025-11-03 13:09:01 +01:00
37 lines
975 B
TypeScript
37 lines
975 B
TypeScript
import { t } from "./i18n.js";
|
|
import toastService from "./toast.js";
|
|
|
|
function copyImageReferenceToClipboard($imageWrapper: JQuery<HTMLElement>) {
|
|
try {
|
|
$imageWrapper.attr("contenteditable", "true");
|
|
selectImage($imageWrapper.get(0));
|
|
|
|
const success = document.execCommand("copy");
|
|
|
|
if (success) {
|
|
toastService.showMessage(t("image.copied-to-clipboard"));
|
|
} else {
|
|
toastService.showAndLogError(t("image.cannot-copy"));
|
|
}
|
|
} finally {
|
|
window.getSelection()?.removeAllRanges();
|
|
$imageWrapper.removeAttr("contenteditable");
|
|
}
|
|
}
|
|
|
|
function selectImage(element: HTMLElement | undefined) {
|
|
if (!element) {
|
|
return;
|
|
}
|
|
|
|
const selection = window.getSelection();
|
|
const range = document.createRange();
|
|
range.selectNodeContents(element);
|
|
selection?.removeAllRanges();
|
|
selection?.addRange(range);
|
|
}
|
|
|
|
export default {
|
|
copyImageReferenceToClipboard
|
|
};
|