Skip to content

Commit cbf8e6b

Browse files
committed
Change handling of theme strings to allow multiple classes
1 parent 55dae62 commit cbf8e6b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/codemirror.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var CodeMirror = (function() {
2424
'<div style="overflow: hidden; position: relative; width: 1px; height: 0px;">' + // Wraps and hides input textarea
2525
'<textarea style="position: absolute; padding: 0; width: 1px;" wrap="off" ' +
2626
'autocorrect="off" autocapitalize="off"></textarea></div>' +
27-
'<div class="CodeMirror-scroll cm-s-' + options.theme + '">' +
27+
'<div class="CodeMirror-scroll">' +
2828
'<div style="position: relative">' + // Set to the height of the text, causes scrolling
2929
'<div style="position: relative">' + // Moved around its parent to cover visible view
3030
'<div class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div>' +
@@ -41,6 +41,7 @@ var CodeMirror = (function() {
4141
mover = code.firstChild, gutter = mover.firstChild, gutterText = gutter.firstChild,
4242
lineSpace = gutter.nextSibling.firstChild, measure = lineSpace.firstChild,
4343
cursor = measure.nextSibling, lineDiv = cursor.nextSibling;
44+
themeChanged();
4445
// Needed to hide big blue blinking cursor on Mobile Safari
4546
if (/AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent)) input.style.width = "0px";
4647
if (!webkit) lineSpace.draggable = true;
@@ -140,7 +141,7 @@ var CodeMirror = (function() {
140141
options[option] = value;
141142
if (option == "mode" || option == "indentUnit") loadMode();
142143
else if (option == "readOnly" && value) {onBlur(); input.blur();}
143-
else if (option == "theme") scroller.className = scroller.className.replace(/cm-s-\w+/, "cm-s-" + value);
144+
else if (option == "theme") themeChanged();
144145
else if (option == "lineWrapping" && oldVal != value) operation(wrappingChanged)();
145146
else if (option == "tabSize") operation(tabsChanged)();
146147
if (option == "lineNumbers" || option == "gutter" || option == "firstLineNumber" || option == "theme")
@@ -1188,6 +1189,10 @@ var CodeMirror = (function() {
11881189
tabText = computeTabText();
11891190
updateDisplay(true);
11901191
}
1192+
function themeChanged() {
1193+
scroller.className = scroller.className.replace(/\s*cm-s-\w+/g, "") +
1194+
options.theme.replace(/(^|\s)\s*/g, " cm-s-");
1195+
}
11911196

11921197
function TextMarker() { this.set = []; }
11931198
TextMarker.prototype.clear = operation(function() {

manual.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ <h2 id="config">Configuration</h2>
131131
CSS file defining the corresponding <code>.cm-s-[name]</code>
132132
styles is loaded (see
133133
the <a href="theme/"><code>theme</code></a> directory in the
134-
distribution).</dd>
134+
distribution). The default is <code>"default"</code>, for which
135+
colors are included in <code>codemirror.css</code>. It is
136+
possible to use multiple theming classes at once—for
137+
example <code>"foo bar"</code> will assign both
138+
the <code>cm-s-foo</code> and the <code>cm-s-bar</code> classes
139+
to the editor.</dd>
135140

136141
<dt id="option_indentUnit"><code>indentUnit (integer)</code></dt>
137142
<dd>How many spaces a block (whatever that means in the edited

0 commit comments

Comments
 (0)