Skip to content

Build your personal knowledge base with Trilium Notes

chore(client/ts): port services/image

Elian Doranf15bebd330e5
diff --git a/src/public/app/services/image.js b/src/public/app/services/image.ts
similarity index 66%
rename from src/public/app/services/image.js
rename to src/public/app/services/image.ts
index f732e843c1..deedc7c0e7 100644
--- a/src/public/app/services/image.js
+++ b/src/public/app/services/image.ts
@@ -1,6 +1,7 @@
+import { t } from "./i18n.js";
import toastService from "./toast.js";
-function copyImageReferenceToClipboard($imageWrapper) {
+function copyImageReferenceToClipboard($imageWrapper: JQuery<HTMLElement>) {
try {
$imageWrapper.attr('contenteditable', 'true');
selectImage($imageWrapper.get(0));
@@ -14,17 +15,21 @@ function copyImageReferenceToClipboard($imageWrapper) {
}
}
finally {
- window.getSelection().removeAllRanges();
+ window.getSelection()?.removeAllRanges();
$imageWrapper.removeAttr('contenteditable');
}
}
-function selectImage(element) {
+function selectImage(element: HTMLElement | undefined) {
+ if (!element) {
+ return;
+ }
+
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(element);
- selection.removeAllRanges();
- selection.addRange(range);
+ selection?.removeAllRanges();
+ selection?.addRange(range);
}
export default {