Support pasting URLs over selection text in the textarea editor. Does not work in EasyMDE and I don't intend to support it. Image paste works as usual in both Textarea and EasyMDE. The new `replaceTextareaSelection` function changes textarea content via [`insertText`](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand#using_inserttext) command, which preserves history, e.g. `CTRL-Z` works and is also demostrated below. We should later refactor the image paste code to use the same function because it currently destroys history. Overriding the formatting via `Shift` key is supported as well, e.g. `Ctrl+Shift+V` will insert the URL as-is, like on GitHub. 
		
			
				
	
	
		
			16 lines
		
	
	
		
			334 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			16 lines
		
	
	
		
			334 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| export function pathEscapeSegments(s) {
 | |
|   return s.split('/').map(encodeURIComponent).join('/');
 | |
| }
 | |
| 
 | |
| function stripSlash(url) {
 | |
|   return url.endsWith('/') ? url.slice(0, -1) : url;
 | |
| }
 | |
| 
 | |
| export function isUrl(url) {
 | |
|   try {
 | |
|     return stripSlash((new URL(url).href)).trim() === stripSlash(url).trim();
 | |
|   } catch {
 | |
|     return false;
 | |
|   }
 | |
| }
 |