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";
 | 
					import toastService from "./toast.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function copyImageReferenceToClipboard($imageWrapper) {
 | 
					function copyImageReferenceToClipboard($imageWrapper: JQuery<HTMLElement>) {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
        $imageWrapper.attr('contenteditable', 'true');
 | 
					        $imageWrapper.attr('contenteditable', 'true');
 | 
				
			||||||
        selectImage($imageWrapper.get(0));
 | 
					        selectImage($imageWrapper.get(0));
 | 
				
			||||||
@ -14,17 +15,21 @@ function copyImageReferenceToClipboard($imageWrapper) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    finally {
 | 
					    finally {
 | 
				
			||||||
        window.getSelection().removeAllRanges();
 | 
					        window.getSelection()?.removeAllRanges();
 | 
				
			||||||
        $imageWrapper.removeAttr('contenteditable');
 | 
					        $imageWrapper.removeAttr('contenteditable');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function selectImage(element) {
 | 
					function selectImage(element: HTMLElement | undefined) {
 | 
				
			||||||
 | 
					    if (!element) {
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    const selection = window.getSelection();
 | 
					    const selection = window.getSelection();
 | 
				
			||||||
    const range = document.createRange();
 | 
					    const range = document.createRange();
 | 
				
			||||||
    range.selectNodeContents(element);
 | 
					    range.selectNodeContents(element);
 | 
				
			||||||
    selection.removeAllRanges();
 | 
					    selection?.removeAllRanges();
 | 
				
			||||||
    selection.addRange(range);
 | 
					    selection?.addRange(range);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user