zhuguifei
2026-03-10 58402bd5e762361363a0f7d7907153c77dbb819f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
    封装代码编辑器
*/
 
Edo.controls.CodeEditor = function(){
 
    Edo.controls.CodeEditor.superclass.constructor.call(this);
};
Edo.controls.CodeEditor.extend(Edo.controls.TextArea,{
    minWidth: 120,
    minHeight: 50,
    elCls: 'e-codeeditor e-div  e-text',
    path: "/",
    createChildren: function(el){
        Edo.controls.CodeEditor.superclass.createChildren.call(this, el);        
        
        var w = isNaN(this.realWidth) ? this.defaultWidth : this.realWidth-1;
        var h = isNaN(this.realHeight) ? this.defaultHeight : this.realHeight-1; 
        
               
        this.editor = CodeMirror.fromTextArea(this.field, {
            width: w+'px',
            height: h+"px",
            parserfile: ["tokenizejavascript.js", "parsejavascript.js"],
            stylesheet: [this.path+"css/jscolors.css"],
            path: this.path+'js/'
            //,lineNumbers: true
        });
        
    },
    
    syncSize: function(){
        Edo.controls.CodeEditor.superclass.syncSize.a(this, arguments);
        
        this.editor.wrapping.style.width = (this.realWidth-1)+'px';
        this.editor.wrapping.style.height = (this.realHeight-1)+"px";
        
        Edo.util.Dom.setSize(this.el, this.realWidth, this.realHeight);
    },
    _setText: function(text){
        this.text = text;
        if(this.editor) {
            try{
                this.editor.setCode(text);
            }catch(e){
                this._setText.defer(100, this,[text]);
            }
        }
    },
    _getText: function(text){
        if(this.editor) this.text = this.editor.getCode();        
        return this.text;
    }
});
Edo.controls.CodeEditor.regType('codeeditor');