Show
Ignore:
Timestamp:
01/10/09 22:08:01 (4 years ago)
Author:
hoge1e3
Message:
 
Location:
lang/javascript/nohada/js
Files:
3 added
2 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/nohada/js/Key.js

    r28244 r28269  
    22        var t=new TextEditor("this\nis\na\nTest"); 
    33        TagBuilder.write(t); 
    4         document.onkeydown=function (e) {return t.processKeyEvent(e);} 
     4        initTextEditorCommand(t); 
     5        var st=tag("span"); 
     6        TagBuilder.write(st); 
     7        document.onkeydown=function (e) { 
     8                st.set(e.keyCode); 
     9                return t.processKeyDownEvent(e); 
     10        } 
     11        document.onkeyup=function (e) { 
     12                st.set(e.keyCode); 
     13                return t.processKeyUpEvent(e); 
     14        } 
    515} 
    616function start2() { 
  • lang/javascript/nohada/js/TextEditor.class.js

    r28244 r28269  
    22        initialize: function (content) { 
    33                this.content=content+"\n"; 
     4                this.keyCommands={}; 
     5                this.shiftState=0; 
    46        }, 
    57        toHTML: function () { 
     
    3133                var curSel=cursor.pos; 
    3234                var n=this.createLetter(str); 
    33                 curSel.prev.next=n; 
    34                 n.prev=curSel.prev; 
     35                var p=curSel.prev; 
     36                if (p) { 
     37                        p.next=n; 
     38                        n.prev=p; 
     39                } 
    3540                n.next=curSel; 
    3641                curSel.prev=n; 
    3742                curSel.insertBefore(n); 
    3843        }, 
    39         processKeyEvent: function (e) { 
    40                 switch (e.keyCode) { 
    41                   case 39: this.cursor.forward(); 
    42                         break; 
    43                   case 37: this.cursor.back(); 
    44                         break; 
    45                   default: this.insertAt(""+String.fromCharCode(e.keyCode)); 
    46                 } 
    47                 return e.keyCode!=9; 
     44        addKeyCommand: function (keyCode,shiftState,command) { 
     45                this.keyCommands[keyCode+shiftState*256]=command; 
     46        }, 
     47        processShiftOffEvent: function (e,key,state) { 
     48                if (e.keyCode==key) { 
     49                        this.shiftState&=~state; 
     50                }                
     51        }, 
     52        processKeyUpEvent: function (e) { 
     53                this.processShiftOffEvent(e,this.KEY_SHIFT,this.SS_SHIFT); 
     54                this.processShiftOffEvent(e,this.KEY_CTRL,this.SS_CTRL); 
     55                this.processShiftOffEvent(e,this.KEY_ALT,this.SS_ALT); 
     56        }, 
     57        processShiftOnEvent: function (e,key,state) { 
     58                if (e.keyCode==key) { 
     59                        this.shiftState|=state; 
     60                }                
     61        }, 
     62        processKeyDownEvent: function (e) { 
     63                this.processShiftOnEvent(e,this.KEY_SHIFT,this.SS_SHIFT); 
     64                this.processShiftOnEvent(e,this.KEY_CTRL,this.SS_CTRL); 
     65                this.processShiftOnEvent(e,this.KEY_ALT,this.SS_ALT); 
     66                var f=this.keyCommands[e.keyCode+this.shiftState*256]; 
     67                if (f) return f.apply(this,[e]); 
     68                return true; 
    4869        }, 
    4970        createCursor: function () { 
    5071                return new this.Cursor(this); 
    5172        }, 
     73        KEY_SHIFT:16, 
     74        KEY_CTRL:17, 
     75        KEY_ALT:18, 
     76        SS_SHIFT: 1, 
     77        SS_CTRL: 2, 
     78        SS_ALT: 4, 
    5279        Cursor: Class.create({ 
    5380                initialize: function (textEditor) {