File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed
Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html >
3+ < head >
4+ < title > CodeMirror 2: Mode-Changing Demo</ title >
5+ < link rel ="stylesheet " href ="../lib/codemirror.css ">
6+ < script src ="../lib/codemirror.js "> </ script >
7+ < link rel ="stylesheet " href ="../theme/default.css ">
8+ < script src ="../mode/javascript/javascript.js "> </ script >
9+ < script src ="../mode/scheme/scheme.js "> </ script >
10+ < link rel ="stylesheet " href ="../css/docs.css ">
11+
12+ < style type ="text/css ">
13+ .CodeMirror {border : 1px solid black;}
14+ </ style >
15+ </ head >
16+ < body >
17+ < h1 > CodeMirror 2: Mode-Changing demo</ h1 >
18+
19+ < form > < textarea id ="code " name ="code ">
20+ ;; If there is Scheme code in here, the editor will be in Scheme mode.
21+ ;; If you put in JS instead, it'll switch to JS mode.
22+
23+ (define (double x)
24+ (* x x))
25+ </ textarea > </ form >
26+
27+ < p > On changes to the content of the above editor, a (crude) script
28+ tries to auto-detect the language used, and switches the editor to
29+ either JavaScript or Scheme mode based on that.</ p >
30+
31+ < script >
32+ var editor = CodeMirror . fromTextArea ( document . getElementById ( "code" ) , {
33+ mode : "scheme" ,
34+ lineNumbers : true ,
35+ matchBrackets : true ,
36+ tabMode : "indent" ,
37+ onChange : function ( ) {
38+ clearTimeout ( pending ) ;
39+ setTimeout ( update , 400 ) ;
40+ }
41+ } ) ;
42+ var pending ;
43+ function update ( ) {
44+ editor . setOption ( "mode" , / ^ \s * [ ; \( ] / . test ( editor . getValue ( ) ) ? "scheme" : "javascript" ) ;
45+ }
46+ </ script >
47+ </ body >
48+ </ html >
Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ <h2 style="margin-top: 0">Usage demos:</h2>
6767 < li > < a href ="demo/theme.html "> Theming</ a > </ li >
6868 < li > < a href ="demo/runmode.html "> Stand-alone highlighting</ a > </ li >
6969 < li > < a href ="demo/fullscreen.html "> Full-screen editing</ a > </ li >
70+ < li > < a href ="demo/changemode.html "> Mode auto-changing</ a > </ li >
7071 </ ul >
7172
7273 </ div > </ div >
You can’t perform that action at this time.
0 commit comments