Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support blank lines in CodeMirror.multiplexingMode

This adds a blankLine method that calls the current mode's blankLine if
it has one. It has allows switching on a blank line if "\n" is specified
for "open" or "close".
  • Loading branch information...
commit 4b5a298f159f5a480772ad1bf42837697f232a01 1 parent f3992b2
@MasonM MasonM authored marijnh committed
Showing with 20 additions and 0 deletions.
  1. +2 −0  doc/manual.html
  2. +18 −0 lib/util/multiplex.js
View
2  doc/manual.html
@@ -949,6 +949,8 @@ <h2 id="addons">Add-ons</h2>
the <code>open</code> fields of the passed objects. When in a
sub-mode, it will go back to the top mode again when
the <code>close</code> string is encountered.
+ Pass <code>"\n"</code> for <code>open</code> or <code>close</code>
+ if you want to switch on a blank line.
When <code>delimStyle</code> is specified, it will be the token
style returned for the delimiter tokens. The outer mode will not
see the content between the delimiters.
View
18 lib/util/multiplex.js
@@ -68,6 +68,24 @@ CodeMirror.multiplexingMode = function(outer /*, others */) {
return mode.indent(state.innerActive ? state.inner : state.outer, textAfter);
},
+ blankLine: function(state) {
+ var mode = state.innerActive ? state.innerActive.mode : outer;
+ if (mode.blankLine) {
+ mode.blankLine(state.innerActive ? state.inner : state.outer);
+ }
+ if (!state.innerActive) {
+ for (var i = 0; i < n_others; ++i) {
+ var other = others[i];
+ if (other.open === "\n") {
+ state.innerActive = other;
+ state.inner = CodeMirror.startState(other.mode, mode.indent ? mode.indent(state.outer, "") : 0);
+ }
+ }
+ } else if (mode.close === "\n") {
+ state.innerActive = state.inner = null;
+ }
+ },
+
electricChars: outer.electricChars,
innerMode: function(state) {
Please sign in to comment.
Something went wrong with that request. Please try again.