mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	chore(client/ts): port services/image
This commit is contained in:
		
							parent
							
								
									14dd3a0021
								
							
						
					
					
						commit
						f15bebd330
					
				@ -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 {
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user