11import  { imageInfo }  from  '../../utils/image.ts' ; 
2- import  { replaceTextareaSelection }  from  '../../utils/dom.ts' ; 
32import  { isUrl }  from  '../../utils/url.ts' ; 
43import  { textareaInsertText ,  triggerEditorContentChanged }  from  './EditorMarkdown.ts' ; 
54import  { 
65  DropzoneCustomEventRemovedFile , 
76  DropzoneCustomEventUploadDone , 
87  generateMarkdownLinkForAttachment , 
98}  from  '../dropzone.ts' ; 
9+ import  { subscribe }  from  '@github/paste-markdown' ; 
1010import  type  CodeMirror  from  'codemirror' ; 
1111import  type  EasyMDE  from  'easymde' ; 
1212import  type  { DropzoneFile }  from  'dropzone' ; 
@@ -129,35 +129,20 @@ export function pasteAsMarkdownLink(textarea: {value: string, selectionStart: nu
129129  return  asMarkdownLink  ? `[${ selectedText } ${ trimmedText }   : null ; 
130130} 
131131
132- function  handleClipboardText ( textarea : HTMLTextAreaElement ,  e : ClipboardEvent ,  pastedText : string ,  isShiftDown : boolean )  { 
133-   // pasting with "shift" means "paste as original content" in most applications 
134-   if  ( isShiftDown )  return ;  // let the browser handle it 
135- 
136-   // when pasting links over selected text, turn it into [text](link) 
137-   const  pastedAsMarkdown  =  pasteAsMarkdownLink ( textarea ,  pastedText ) ; 
138-   if  ( pastedAsMarkdown )  { 
139-     e . preventDefault ( ) ; 
140-     replaceTextareaSelection ( textarea ,  pastedAsMarkdown ) ; 
141-   } 
142-   // else, let the browser handle it 
143- } 
144- 
145- // extract text and images from "paste" event 
146- function  getPastedContent ( e : ClipboardEvent )  { 
147-   const  images  =  [ ] ; 
132+ function  getPastedImages ( e : ClipboardEvent )  { 
133+   const  images : Array < File >  =  [ ] ; 
148134  for  ( const  item  of  e . clipboardData ?. items  ??  [ ] )  { 
149135    if  ( item . type ?. startsWith ( 'image/' ) )  { 
150136      images . push ( item . getAsFile ( ) ) ; 
151137    } 
152138  } 
153-   const  text  =  e . clipboardData ?. getData ?.( 'text' )  ??  '' ; 
154-   return  { text,  images} ; 
139+   return  images ; 
155140} 
156141
157142export  function  initEasyMDEPaste ( easyMDE : EasyMDE ,  dropzoneEl : HTMLElement )  { 
158143  const  editor  =  new  CodeMirrorEditor ( easyMDE . codemirror  as  any ) ; 
159144  easyMDE . codemirror . on ( 'paste' ,  ( _ ,  e )  =>  { 
160-     const  { images}  =  getPastedContent ( e ) ; 
145+     const  images  =  getPastedImages ( e ) ; 
161146    if  ( ! images . length )  return ; 
162147    handleUploadFiles ( editor ,  dropzoneEl ,  images ,  e ) ; 
163148  } ) ; 
@@ -173,19 +158,11 @@ export function initEasyMDEPaste(easyMDE: EasyMDE, dropzoneEl: HTMLElement) {
173158} 
174159
175160export  function  initTextareaEvents ( textarea : HTMLTextAreaElement ,  dropzoneEl : HTMLElement )  { 
176-   let  isShiftDown  =  false ; 
177-   textarea . addEventListener ( 'keydown' ,  ( e : KeyboardEvent )  =>  { 
178-     if  ( e . shiftKey )  isShiftDown  =  true ; 
179-   } ) ; 
180-   textarea . addEventListener ( 'keyup' ,  ( e : KeyboardEvent )  =>  { 
181-     if  ( ! e . shiftKey )  isShiftDown  =  false ; 
182-   } ) ; 
161+   subscribe ( textarea ) ;  // enable paste-related features 
183162  textarea . addEventListener ( 'paste' ,  ( e : ClipboardEvent )  =>  { 
184-     const  { images,  text }   =   getPastedContent ( e ) ; 
163+     const  images   =   getPastedImages ( e ) ; 
185164    if  ( images . length  &&  dropzoneEl )  { 
186165      handleUploadFiles ( new  TextareaEditor ( textarea ) ,  dropzoneEl ,  images ,  e ) ; 
187-     }  else  if  ( text )  { 
188-       handleClipboardText ( textarea ,  e ,  text ,  isShiftDown ) ; 
189166    } 
190167  } ) ; 
191168  textarea . addEventListener ( 'drop' ,  ( e : DragEvent )  =>  { 
0 commit comments