Skip to content

Commit 2bf353a

Browse files
committed
Add defineExtension API function
1 parent 622dec5 commit 2bf353a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/codemirror.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,10 @@ var CodeMirror = (function() {
14411441
to: function() {if (this.atOccurrence) return copyPos(this.pos.to);}
14421442
};
14431443

1444+
for (var ext in extensions)
1445+
if (extensions.propertyIsEnumerable(ext) &&
1446+
!instance.propertyIsEnumerable(ext))
1447+
instance[ext] = extensions[ext];
14441448
return instance;
14451449
} // (end of function CodeMirror)
14461450

@@ -1507,6 +1511,11 @@ var CodeMirror = (function() {
15071511
return list;
15081512
};
15091513

1514+
var extensions = {};
1515+
CodeMirror.defineExtension = function(name, func) {
1516+
extensions[name] = func;
1517+
};
1518+
15101519
CodeMirror.fromTextArea = function(textarea, options) {
15111520
if (!options) options = {};
15121521
options.value = textarea.value;

manual.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,12 @@ <h2 id="api">Programming API</h2>
581581
the editor's current content).</dd>
582582
</dl>
583583

584+
<p id="defineExtension">If you want define extra methods in terms
585+
of the CodeMirror API, is it possible to
586+
use <code>CodeMirror.defineExtension(name, value)</code>. This
587+
will cause the given value (usually a method) to be added to all
588+
CodeMirror instances created from then on.</p>
589+
584590
<h2 id="modeapi">Writing CodeMirror Modes</h2>
585591

586592
<p>Modes typically consist of a JavaScript file and a CSS file.

0 commit comments

Comments
 (0)