1212"use strict" ;
1313
1414CodeMirror . multiplexingMode = function ( outer /*, others */ ) {
15- // Others should be {open, close, mode [, delimStyle] [, innerStyle]} objects
15+ // Others should be {open, close, mode [, delimStyle] [, innerStyle] [, parseDelimiters] } objects
1616 var others = Array . prototype . slice . call ( arguments , 1 ) ;
1717
1818 function indexOf ( string , pattern , from , returnEnd ) {
@@ -29,15 +29,17 @@ CodeMirror.multiplexingMode = function(outer /*, others */) {
2929 return {
3030 outer : CodeMirror . startState ( outer ) ,
3131 innerActive : null ,
32- inner : null
32+ inner : null ,
33+ startingInner : false
3334 } ;
3435 } ,
3536
3637 copyState : function ( state ) {
3738 return {
3839 outer : CodeMirror . copyState ( outer , state . outer ) ,
3940 innerActive : state . innerActive ,
40- inner : state . innerActive && CodeMirror . copyState ( state . innerActive . mode , state . inner )
41+ inner : state . innerActive && CodeMirror . copyState ( state . innerActive . mode , state . inner ) ,
42+ startingInner : state . startingInner
4143 } ;
4244 } ,
4345
@@ -49,6 +51,7 @@ CodeMirror.multiplexingMode = function(outer /*, others */) {
4951 var found = indexOf ( oldContent , other . open , stream . pos ) ;
5052 if ( found == stream . pos ) {
5153 if ( ! other . parseDelimiters ) stream . match ( other . open ) ;
54+ state . startingInner = ! ! other . parseDelimiters
5255 state . innerActive = other ;
5356
5457 // Get the outer indent, making sure to handle CodeMirror.Pass
@@ -74,7 +77,8 @@ CodeMirror.multiplexingMode = function(outer /*, others */) {
7477 state . innerActive = state . inner = null ;
7578 return this . token ( stream , state ) ;
7679 }
77- var found = curInner . close ? indexOf ( oldContent , curInner . close , stream . pos , curInner . parseDelimiters ) : - 1 ;
80+ var found = curInner . close && ! state . startingInner ?
81+ indexOf ( oldContent , curInner . close , stream . pos , curInner . parseDelimiters ) : - 1 ;
7882 if ( found == stream . pos && ! curInner . parseDelimiters ) {
7983 stream . match ( curInner . close ) ;
8084 state . innerActive = state . inner = null ;
@@ -83,6 +87,7 @@ CodeMirror.multiplexingMode = function(outer /*, others */) {
8387 if ( found > - 1 ) stream . string = oldContent . slice ( 0 , found ) ;
8488 var innerToken = curInner . mode . token ( stream , state . inner ) ;
8589 if ( found > - 1 ) stream . string = oldContent ;
90+ else if ( stream . pos > stream . start ) state . startingInner = false
8691
8792 if ( found == stream . pos && curInner . parseDelimiters )
8893 state . innerActive = state . inner = null ;
0 commit comments