@@ -45,7 +45,7 @@ export const NodeEditor: m.Component = {
4545 if ( node . parent && node . parent . hasComponent ( Document ) && window . Editor ) {
4646 editor = CodeMirrorEditor ;
4747 }
48- return m ( editor , { id, getter, setter, display, onkeydown, onfocus, oninput, placeholder} ) ;
48+ return m ( editor , { id, getter, setter, display, onkeydown, onfocus, oninput, placeholder, workbench , path } ) ;
4949 }
5050}
5151
@@ -145,7 +145,7 @@ export const TextAreaEditor: m.Component<Attrs, State> = {
145145 onupdate ( ) {
146146 this . updateHeight ( ) ;
147147 } ,
148- view ( { attrs : { id, onkeydown, onfocus, onblur, oninput, getter, setter, display, placeholder} , state} ) {
148+ view ( { attrs : { id, onkeydown, onfocus, onblur, oninput, getter, setter, display, placeholder, path , workbench } , state} ) {
149149 const value = ( state . editing )
150150 ? state . buffer
151151 : ( display ) ? display ( ) : getter ( ) ;
@@ -180,6 +180,29 @@ export const TextAreaEditor: m.Component<Attrs, State> = {
180180 oninput ( e ) ;
181181 }
182182 }
183+ const handlePaste = ( e ) => {
184+ const textData = e . clipboardData . getData ( 'Text' ) ;
185+ if ( textData . length > 0 ) {
186+ e . preventDefault ( ) ;
187+ e . stopPropagation ( ) ;
188+
189+ const lines = textData . split ( '\n' ) . map ( line => line . trim ( ) ) . filter ( line => line . length > 0 ) ;
190+ state . buffer = lines . shift ( ) ;
191+ setter ( state . buffer , true ) ;
192+
193+ let node = path . node ;
194+ for ( const line of lines ) {
195+ const newNode = workbench . workspace . new ( line ) ;
196+ newNode . parent = node . parent ;
197+ newNode . siblingIndex = node . siblingIndex + 1 ;
198+ m . redraw . sync ( ) ;
199+ const p = path . clone ( ) ;
200+ p . pop ( ) ;
201+ workbench . focus ( p . append ( newNode ) ) ;
202+ node = newNode ;
203+ }
204+ }
205+ }
183206
184207 return (
185208 < div class = "text-editor" >
@@ -189,6 +212,7 @@ export const TextAreaEditor: m.Component<Attrs, State> = {
189212 onfocus = { startEdit }
190213 onblur = { finishEdit }
191214 oninput = { edit }
215+ onpaste = { handlePaste }
192216 placeholder = { placeholder }
193217 onkeydown = { onkeydown || defaultKeydown }
194218 value = { value } > { value } </ textarea >
0 commit comments