@@ -51,7 +51,7 @@ export default {
5151 props: {
5252 name: String ,
5353 autofocus: Boolean ,
54- modals: Boolean ,
54+ modals: Boolean ,
5555 blank: Boolean ,
5656 invisibles: Boolean ,
5757 buttons: [Boolean , Array ],
@@ -144,14 +144,18 @@ export default {
144144 let tokenType = _editor .getTokenTypeAt (pos)
145145 this .setTokenType (tokenType, pos)
146146 })
147-
147+
148148 // Emit changed value
149149 this .editor .on (' focus' , _editor => {
150150 this .$root .$emit (' md-closeDropdowns' )
151151 })
152152
153153 // Additional styling
154154 this .editor .on (' renderLine' , this .renderLine .bind (this ));
155+
156+ // Accept dragText from Kirby sections
157+ this .editor .on (' drop' , this .onDrop .bind (this ))
158+
155159 },
156160 watch: {
157161 value (newVal , oldVal ) {
@@ -258,7 +262,7 @@ export default {
258262 if (this .currentDialog == ' images' ) {
259263 let tag = ' (image: ' + file .uuid + ' )'
260264 this .insert (tag)
261- }
265+ }
262266 // if we're inserting a file
263267 else {
264268 let selection = doc .getSelection ()
@@ -291,7 +295,7 @@ export default {
291295 if (! tokenType || tokenType == null ) {
292296 this .currentTokenType = null
293297 return
294- }
298+ }
295299
296300 // init an object
297301 let main = undefined
@@ -336,7 +340,7 @@ export default {
336340 // secondary type
337341 else if (type .startsWith (' header-' ) || type .startsWith (' kirbytag-' )) {
338342 secondary = type .replace (' header-' , ' heading-' )
339- }
343+ }
340344 })
341345
342346 // set the type object as current token type
@@ -382,7 +386,7 @@ export default {
382386
383387 indent += this .getActualFormattingWidth (cm, parts[i]);
384388 }
385-
389+
386390 el .style .setProperty (' --cm-block-indent' , indent);
387391
388392 } else if (formatting .classList .contains (' cm-formatting-header' )) {
@@ -441,25 +445,25 @@ export default {
441445
442446 indent += parts[i].textContent .length ;
443447 }
444-
448+
445449 el .style .setProperty (' --cm-block-indent' , indent);
446450
447451 } else if (formatting .classList .contains (' cm-formatting-header' )) {
448452 // Header
449453 const regex = new RegExp (' cm-formatting-header-([1-6])' );
450454 const level = parseInt (regex .exec (content .children [0 ].className )[1 ], 10 );
451-
455+
452456 el .style .setProperty (' --cm-block-indent' , level + 1 );
453457
454458 } else if (content .querySelector (' .cm-formatting-list' )) {
455459 // List item
456460
457461 const nodes = content .childNodes ; // We need all text nodes as well
458-
462+
459463 let indent = 0 ;
460464
461465 for (let i = 0 , l = nodes .length ; i < l; i++ ) {
462-
466+
463467 const node = nodes[i];
464468
465469 if (node .nodeType === Node .TEXT_NODE ) {
@@ -490,12 +494,12 @@ export default {
490494 * Gets the actual width of a text node or element node in the editor.
491495 */
492496 getActualFormattingWidth (cm , target ) {
493-
494- const wrapper = cm .getWrapperElement ();
497+
498+ const wrapper = cm .getWrapperElement ();
495499 const extraStyles = ' position: absolute !important; top: -1000px !important; white-space: pre !important;' ;
496500
497501 let clone;
498-
502+
499503 if (target .nodeType === Node .TEXT_NODE ) {
500504 // Use parent element’s styles for measuring text nodes
501505 clone = document .createElement (' span' );
@@ -508,12 +512,26 @@ export default {
508512 }
509513
510514 wrapper .appendChild (clone);
511-
515+
512516 const width = clone .getBoundingClientRect ().width ;
513517 clone .remove ();
514-
518+
515519 return width;
516520 },
521+
522+ /**
523+ * Handles the drop event from CodeMirror
524+ * Allows it to accept Kirby DragTexts
525+ */
526+ onDrop (cm , e ) {
527+ const drag = this .$store .state .drag ;
528+
529+ if (drag && drag .type === " text" ) {
530+ this .editorFocus ()
531+ this .insert (drag .data )
532+ e .preventDefault ()
533+ }
534+ }
517535 }
518536}
519537 </script >
0 commit comments