@@ -263,6 +263,11 @@ function toggleCodeBlock(editor) {
263263 return line . styles && line . styles [ 2 ] && line . styles [ 2 ] . indexOf ( "formatting-code-block" ) !== - 1 ;
264264 }
265265
266+ function token_state ( token ) {
267+ // base goes an extra level deep when mode backdrops are used, e.g. spellchecker on
268+ return token . state . base . base || token . state . base ;
269+ }
270+
266271 function code_type ( cm , line_num , line , firstTok , lastTok ) {
267272 /*
268273 * Return "single", "indented", "fenced" or false
@@ -280,13 +285,13 @@ function toggleCodeBlock(editor) {
280285 ch : line . text . length - 1
281286 } ) ) ;
282287 var types = firstTok . type ? firstTok . type . split ( " " ) : [ ] ;
283- if ( lastTok && lastTok . state . base . indentedCode ) {
288+ if ( lastTok && token_state ( lastTok ) . indentedCode ) {
284289 // have to check last char, since first chars of first line aren"t marked as indented
285290 return "indented" ;
286291 } else if ( types . indexOf ( "comment" ) === - 1 ) {
287292 // has to be after "indented" check, since first chars of first indented line aren"t marked as such
288293 return false ;
289- } else if ( firstTok . state . base . fencedChars || lastTok . state . base . fencedChars || fencing_line ( line ) ) {
294+ } else if ( token_state ( firstTok ) . fencedChars || token_state ( lastTok ) . fencedChars || fencing_line ( line ) ) {
290295 return "fenced" ;
291296 } else {
292297 return "single" ;
@@ -358,7 +363,7 @@ function toggleCodeBlock(editor) {
358363 line : block_start ,
359364 ch : 1
360365 } ) ;
361- insertFencingAtSelection ( cm , cur_start , cur_end , fencedTok . state . base . fencedChars ) ;
366+ insertFencingAtSelection ( cm , cur_start , cur_end , token_state ( fencedTok ) . fencedChars ) ;
362367 } else {
363368 // no selection, search for ends of this fenced block
364369 var search_from = cur_start . line ;
@@ -449,7 +454,7 @@ function toggleCodeBlock(editor) {
449454 line : block_end + 1 ,
450455 ch : next_line . text . length - 1
451456 } ) ,
452- next_line_indented = next_line_last_tok && next_line_last_tok . state . base . indentedCode ;
457+ next_line_indented = next_line_last_tok && token_state ( next_line_last_tok ) . indentedCode ;
453458 if ( next_line_indented ) {
454459 cm . replaceRange ( "\n" , {
455460 line : block_end + 1 ,
0 commit comments