@@ -430,21 +430,15 @@ define(function (require, exports, module) {
430
430
if ( sourceBeforeTarget ) {
431
431
// this handles the case when source is before target: insert first, then remove
432
432
if ( insertInside ) {
433
- // Insert as child inside the target element
434
- const targetText = editor . getTextBetween ( targetRangeObj . from , targetRangeObj . to ) ;
435
- const targetElement = targetText . trim ( ) ;
436
-
437
- // Find the position just after the opening tag
438
- const openingTagMatch = targetElement . match ( / ^ < [ ^ > ] * > / ) ;
439
- if ( openingTagMatch ) {
440
- const openingTag = openingTagMatch [ 0 ] ;
433
+ const matchingTagInfo = CodeMirror . findMatchingTag ( editor . _codeMirror , targetRangeObj . from ) ;
434
+ if ( matchingTagInfo && matchingTagInfo . open ) {
441
435
const insertPos = {
442
- line : targetRangeObj . from . line ,
443
- ch : targetRangeObj . from . ch + openingTag . length
436
+ line : matchingTagInfo . open . to . line ,
437
+ ch : matchingTagInfo . open . to . ch
444
438
} ;
445
439
446
- // Add proper indentation for child element
447
- const childIndent = targetIndent + " " ; // 4 spaces more than parent
440
+ const indentInfo = editor . _detectIndent ( ) ;
441
+ const childIndent = targetIndent + indentInfo . indent ;
448
442
_insertElementWithIndentation ( editor , insertPos , true , childIndent , sourceText ) ;
449
443
}
450
444
} else if ( insertAfter ) {
@@ -489,21 +483,15 @@ define(function (require, exports, module) {
489
483
} ;
490
484
491
485
if ( insertInside ) {
492
- // Insert as child inside the target element
493
- const targetText = editor . getTextBetween ( updatedTargetRangeObj . from , updatedTargetRangeObj . to ) ;
494
- const targetElement = targetText . trim ( ) ;
495
-
496
- // Find the position just after the opening tag
497
- const openingTagMatch = targetElement . match ( / ^ < [ ^ > ] * > / ) ;
498
- if ( openingTagMatch ) {
499
- const openingTag = openingTagMatch [ 0 ] ;
486
+ const matchingTagInfo = CodeMirror . findMatchingTag ( editor . _codeMirror , updatedTargetRangeObj . from ) ;
487
+ if ( matchingTagInfo && matchingTagInfo . open ) {
500
488
const insertPos = {
501
- line : updatedTargetRangeObj . from . line ,
502
- ch : updatedTargetRangeObj . from . ch + openingTag . length
489
+ line : matchingTagInfo . open . to . line ,
490
+ ch : matchingTagInfo . open . to . ch
503
491
} ;
504
492
505
- // Add proper indentation for child element
506
- const childIndent = targetIndent + " " ; // 4 spaces more than parent
493
+ const indentInfo = editor . _detectIndent ( ) ;
494
+ const childIndent = targetIndent + indentInfo . indent ;
507
495
_insertElementWithIndentation ( editor , insertPos , true , childIndent , sourceText ) ;
508
496
}
509
497
} else if ( insertAfter ) {
0 commit comments