Subversion Repositories wimsdev

Rev

Rev 4870 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4870 Rev 8476
Line 1... Line 1...
1
/**
1
/**
2
 * Autocompletion class
2
 * Autocompletion class
3
 *
3
 *
4
 * An auto completion box appear while you're writing. It's possible to force it to appear with Ctrl+Space short cut
4
 * An auto completion box appear while you're writing. It's possible to force it to appear with Ctrl+Space short cut
5
 *
5
 *
6
 * Loaded as a plugin inside editArea (everything made here could have been made in the plugin directory)
6
 * Loaded as a plugin inside editArea (everything made here could have been made in the plugin directory)
7
 * But is definitly linked to syntax selection (no need to do 2 different files for color and auto complete for each syntax language)
7
 * But is definitly linked to syntax selection (no need to do 2 different files for color and auto complete for each syntax language)
8
 * and add a too important feature that many people would miss if included as a plugin
8
 * and add a too important feature that many people would miss if included as a plugin
9
 *
9
 *
10
 * - init param: autocompletion_start
10
 * - init param: autocompletion_start
11
 * - Button name: "autocompletion"
11
 * - Button name: "autocompletion"
12
 */  
12
 */
13
 
13
 
14
var EditArea_autocompletion= {
14
var EditArea_autocompletion= {
15
       
15
 
16
        /**
16
        /**
17
         * Get called once this file is loaded (editArea still not initialized)
17
         * Get called once this file is loaded (editArea still not initialized)
18
         *
18
         *
19
         * @return nothing       
19
         * @return nothing
20
         */                    
20
         */
21
        init: function(){      
21
        init: function(){
22
                //      alert("test init: "+ this._someInternalFunction(2, 3));
22
                //      alert("test init: "+ this._someInternalFunction(2, 3));
23
               
23
 
24
                if(editArea.settings["autocompletion"])
24
                if(editArea.settings["autocompletion"])
25
                        this.enabled= true;
25
                        this.enabled= true;
26
                else
26
                else
27
                        this.enabled= false;
27
                        this.enabled= false;
28
                this.current_word               = false;
28
                this.current_word               = false;
Line 32... Line 32...
32
                this.isInMiddleWord             = false;
32
                this.isInMiddleWord             = false;
33
                this.autoSelectIfOneResult      = false;
33
                this.autoSelectIfOneResult      = false;
34
                this.delayBeforeDisplay = 100;
34
                this.delayBeforeDisplay = 100;
35
                this.checkDelayTimer    = false;
35
                this.checkDelayTimer    = false;
36
                this.curr_syntax_str    = '';
36
                this.curr_syntax_str    = '';
37
               
37
 
38
                this.file_syntax_datas  = {};
38
                this.file_syntax_datas  = {};
39
        }
39
        }
40
        /**
40
        /**
41
         * Returns the HTML code for a specific control string or false if this plugin doesn't have that control.
41
         * Returns the HTML code for a specific control string or false if this plugin doesn't have that control.
42
         * A control can be a button, select list or any other HTML item to present in the EditArea user interface.
42
         * A control can be a button, select list or any other HTML item to present in the EditArea user interface.
43
         * Language variables such as {$lang_somekey} will also be replaced with contents from
43
         * Language variables such as {$lang_somekey} will also be replaced with contents from
44
         * the language packs.
44
         * the language packs.
45
         *
45
         *
46
         * @param {string} ctrl_name: the name of the control to add     
46
         * @param {string} ctrl_name: the name of the control to add
47
         * @return HTML code for a specific control or false.
47
         * @return HTML code for a specific control or false.
48
         * @type string or boolean
48
         * @type string or boolean
49
         */    
49
         */
50
        /*,get_control_html: function(ctrl_name){
50
        /*,get_control_html: function(ctrl_name){
51
                switch( ctrl_name ){
51
                switch( ctrl_name ){
52
                        case 'autocompletion':
52
                        case 'autocompletion':
53
                                // Control id, button img, command
53
                                // Control id, button img, command
54
                                return parent.editAreaLoader.get_button_html('autocompletion_but', 'autocompletion.gif', 'toggle_autocompletion', false, this.baseURL);
54
                                return parent.editAreaLoader.get_button_html('autocompletion_but', 'autocompletion.gif', 'toggle_autocompletion', false, this.baseURL);
Line 56... Line 56...
56
                }
56
                }
57
                return false;
57
                return false;
58
        }*/
58
        }*/
59
        /**
59
        /**
60
         * Get called once EditArea is fully loaded and initialised
60
         * Get called once EditArea is fully loaded and initialised
61
         *       
61
         *
62
         * @return nothing
62
         * @return nothing
63
         */                    
63
         */
64
        ,onload: function(){
64
        ,onload: function(){
65
                if(this.enabled)
65
                if(this.enabled)
66
                {
66
                {
67
                        var icon= document.getElementById("autocompletion");
67
                        var icon= document.getElementById("autocompletion");
68
                        if(icon)
68
                        if(icon)
69
                                editArea.switchClassSticky(icon, 'editAreaButtonSelected', true);
69
                                editArea.switchClassSticky(icon, 'editAreaButtonSelected', true);
70
                }
70
                }
71
               
71
 
72
                this.container  = document.createElement('div');
72
                this.container  = document.createElement('div');
73
                this.container.id       = "auto_completion_area";
73
                this.container.id       = "auto_completion_area";
74
                editArea.container.insertBefore( this.container, editArea.container.firstChild );
74
                editArea.container.insertBefore( this.container, editArea.container.firstChild );
75
               
75
 
76
                // add event detection for hiding suggestion box
76
                // add event detection for hiding suggestion box
77
                parent.editAreaLoader.add_event( document, "click", function(){ editArea.plugins['autocompletion']._hide();} );
77
                parent.editAreaLoader.add_event( document, "click", function(){ editArea.plugins['autocompletion']._hide();} );
78
                parent.editAreaLoader.add_event( editArea.textarea, "blur", function(){ editArea.plugins['autocompletion']._hide();} );
78
                parent.editAreaLoader.add_event( editArea.textarea, "blur", function(){ editArea.plugins['autocompletion']._hide();} );
79
               
79
 
80
        }
80
        }
81
       
81
 
82
        /**
82
        /**
83
         * Is called each time the user touch a keyboard key.
83
         * Is called each time the user touch a keyboard key.
84
         *       
84
         *
85
         * @param (event) e: the keydown event
85
         * @param (event) e: the keydown event
86
         * @return true - pass to next handler in chain, false - stop chain execution
86
         * @return true - pass to next handler in chain, false - stop chain execution
87
         * @type boolean         
87
         * @type boolean
88
         */
88
         */
89
        ,onkeydown: function(e){
89
        ,onkeydown: function(e){
90
                if(!this.enabled)
90
                if(!this.enabled)
91
                        return true;
91
                        return true;
92
                       
92
 
93
                if (EA_keys[e.keyCode])
93
                if (EA_keys[e.keyCode])
94
                        letter=EA_keys[e.keyCode];
94
                        letter=EA_keys[e.keyCode];
95
                else
95
                else
96
                        letter=String.fromCharCode(e.keyCode); 
96
                        letter=String.fromCharCode(e.keyCode);
97
                // shown
97
                // shown
98
                if( this._isShown() )
98
                if( this._isShown() )
99
                {      
99
                {
100
                        // if escape, hide the box
100
                        // if escape, hide the box
101
                        if(letter=="Esc")
101
                        if(letter=="Esc")
102
                        {
102
                        {
103
                                this._hide();
103
                                this._hide();
104
                                return false;
104
                                return false;
Line 107... Line 107...
107
                        else if( letter=="Entrer")
107
                        else if( letter=="Entrer")
108
                        {
108
                        {
109
                                var as  = this.container.getElementsByTagName('A');
109
                                var as  = this.container.getElementsByTagName('A');
110
                                // select a suggested entry
110
                                // select a suggested entry
111
                                if( this.selectIndex >= 0 && this.selectIndex < as.length )
111
                                if( this.selectIndex >= 0 && this.selectIndex < as.length )
112
                                {
112
                                {
113
                                        as[ this.selectIndex ].onmousedown();
113
                                        as[ this.selectIndex ].onmousedown();
114
                                        return false
114
                                        return false
115
                                }
115
                                }
116
                                // simply add an enter in the code
116
                                // simply add an enter in the code
117
                                else
117
                                else
Line 130... Line 130...
130
                                this._selectBefore();
130
                                this._selectBefore();
131
                                return false;
131
                                return false;
132
                        }
132
                        }
133
                }
133
                }
134
                // hidden
134
                // hidden
135
                else
135
                else
136
                {
136
                {
137
                       
137
 
138
                }
138
                }
139
               
139
 
140
                // show current suggestion list and do autoSelect if possible (no matter it's shown or hidden)
140
                // show current suggestion list and do autoSelect if possible (no matter it's shown or hidden)
141
                if( letter=="Space" && CtrlPressed(e) )
141
                if( letter=="Space" && CtrlPressed(e) )
142
                {
142
                {
143
                        //parent.console.log('SHOW SUGGEST');
143
                        //parent.console.log('SHOW SUGGEST');
144
                        this.forceDisplay                       = true;
144
                        this.forceDisplay                       = true;
145
                        this.autoSelectIfOneResult      = true;
145
                        this.autoSelectIfOneResult      = true;
146
                        this._checkLetter();
146
                        this._checkLetter();
147
                        return false;
147
                        return false;
148
                }
148
                }
149
               
149
 
150
                // wait a short period for check that the cursor isn't moving
150
                // wait a short period for check that the cursor isn't moving
151
                setTimeout("editArea.plugins['autocompletion']._checkDelayAndCursorBeforeDisplay();", editArea.check_line_selection_timer +5 );
151
                setTimeout("editArea.plugins['autocompletion']._checkDelayAndCursorBeforeDisplay();", editArea.check_line_selection_timer +5 );
152
                this.checkDelayTimer = false;
152
                this.checkDelayTimer = false;
153
                return true;
153
                return true;
154
        }      
154
        }
155
        /**
155
        /**
156
         * Executes a specific command, this function handles plugin commands.
156
         * Executes a specific command, this function handles plugin commands.
157
         *
157
         *
158
         * @param {string} cmd: the name of the command being executed
158
         * @param {string} cmd: the name of the command being executed
159
         * @param {unknown} param: the parameter of the command  
159
         * @param {unknown} param: the parameter of the command
160
         * @return true - pass to next handler in chain, false - stop chain execution
160
         * @return true - pass to next handler in chain, false - stop chain execution
161
         * @type boolean       
161
         * @type boolean
162
         */
162
         */
163
        ,execCommand: function(cmd, param){
163
        ,execCommand: function(cmd, param){
164
                switch( cmd ){
164
                switch( cmd ){
165
                        case 'toggle_autocompletion':
165
                        case 'toggle_autocompletion':
166
                                var icon= document.getElementById("autocompletion");
166
                                var icon= document.getElementById("autocompletion");
Line 216... Line 216...
216
        }
216
        }
217
        // select the next element in the suggested box
217
        // select the next element in the suggested box
218
        ,_selectNext: function()
218
        ,_selectNext: function()
219
        {
219
        {
220
                var as  = this.container.getElementsByTagName('A');
220
                var as  = this.container.getElementsByTagName('A');
221
               
221
 
222
                // clean existing elements
222
                // clean existing elements
223
                for( var i=0; i<as.length; i++ )
223
                for( var i=0; i<as.length; i++ )
224
                {
224
                {
225
                        if( as[i].className )
225
                        if( as[i].className )
226
                                as[i].className = as[i].className.replace(/ focus/g, '');
226
                                as[i].className = as[i].className.replace(/ focus/g, '');
227
                }
227
                }
228
               
228
 
229
                this.selectIndex++;    
229
                this.selectIndex++;
230
                this.selectIndex        = ( this.selectIndex >= as.length || this.selectIndex < 0 ) ? 0 : this.selectIndex;
230
                this.selectIndex        = ( this.selectIndex >= as.length || this.selectIndex < 0 ) ? 0 : this.selectIndex;
231
                as[ this.selectIndex ].className        += " focus";
231
                as[ this.selectIndex ].className        += " focus";
232
        }
232
        }
233
        // select the previous element in the suggested box
233
        // select the previous element in the suggested box
234
        ,_selectBefore: function()
234
        ,_selectBefore: function()
235
        {
235
        {
236
                var as  = this.container.getElementsByTagName('A');
236
                var as  = this.container.getElementsByTagName('A');
237
               
237
 
238
                // clean existing elements
238
                // clean existing elements
239
                for( var i=0; i<as.length; i++ )
239
                for( var i=0; i<as.length; i++ )
240
                {
240
                {
241
                        if( as[i].className )
241
                        if( as[i].className )
242
                                as[i].className = as[ i ].className.replace(/ focus/g, '');
242
                                as[i].className = as[ i ].className.replace(/ focus/g, '');
243
                }
243
                }
244
               
244
 
245
                this.selectIndex--;
245
                this.selectIndex--;
246
               
246
 
247
                this.selectIndex        = ( this.selectIndex >= as.length || this.selectIndex < 0 ) ? as.length-1 : this.selectIndex;
247
                this.selectIndex        = ( this.selectIndex >= as.length || this.selectIndex < 0 ) ? as.length-1 : this.selectIndex;
248
                as[ this.selectIndex ].className        += " focus";
248
                as[ this.selectIndex ].className        += " focus";
249
        }
249
        }
250
        ,_select: function( content )
250
        ,_select: function( content )
251
        {
251
        {
252
                cursor_forced_position  = content.indexOf( '{@}' );
252
                cursor_forced_position  = content.indexOf( '{@}' );
253
                content = content.replace(/{@}/g, '' );
253
                content = content.replace(/{@}/g, '' );
254
                if(editArea.isIE)
-
 
255
                        editArea.getIESelection();
254
                editArea.getIESelection();
256
               
255
 
257
                // retrive the number of matching characters
256
                // retrive the number of matching characters
258
                var start_index = Math.max( 0, editArea.textarea.selectionEnd - content.length );
257
                var start_index = Math.max( 0, editArea.textarea.selectionEnd - content.length );
259
               
258
 
260
                line_string     =       editArea.textarea.value.substring( start_index, editArea.textarea.selectionEnd + 1);
259
                line_string     =       editArea.textarea.value.substring( start_index, editArea.textarea.selectionEnd + 1);
261
                limit   = line_string.length -1;
260
                limit   = line_string.length -1;
262
                nbMatch = 0;
261
                nbMatch = 0;
263
                for( i =0; i<limit ; i++ )
262
                for( i =0; i<limit ; i++ )
264
                {
263
                {
Line 266... Line 265...
266
                                nbMatch = i + 1;
265
                                nbMatch = i + 1;
267
                }
266
                }
268
                // if characters match, we should include them in the selection that will be replaced
267
                // if characters match, we should include them in the selection that will be replaced
269
                if( nbMatch > 0 )
268
                if( nbMatch > 0 )
270
                        parent.editAreaLoader.setSelectionRange(editArea.id, editArea.textarea.selectionStart - nbMatch , editArea.textarea.selectionEnd);
269
                        parent.editAreaLoader.setSelectionRange(editArea.id, editArea.textarea.selectionStart - nbMatch , editArea.textarea.selectionEnd);
271
               
270
 
272
                parent.editAreaLoader.setSelectedText(editArea.id, content );
271
                parent.editAreaLoader.setSelectedText(editArea.id, content );
273
                range= parent.editAreaLoader.getSelectionRange(editArea.id);
272
                range= parent.editAreaLoader.getSelectionRange(editArea.id);
274
               
273
 
275
                if( cursor_forced_position != -1 )
274
                if( cursor_forced_position != -1 )
276
                        new_pos = range["end"] - ( content.length-cursor_forced_position );
275
                        new_pos = range["end"] - ( content.length-cursor_forced_position );
277
                else
276
                else
278
                        new_pos = range["end"];
277
                        new_pos = range["end"];
279
                parent.editAreaLoader.setSelectionRange(editArea.id, new_pos, new_pos);
278
                parent.editAreaLoader.setSelectionRange(editArea.id, new_pos, new_pos);
280
                this._hide();
279
                this._hide();
281
        }
280
        }
282
       
281
 
283
       
282
 
284
        /**
283
        /**
285
         * Parse the AUTO_COMPLETION part of syntax definition files
284
         * Parse the AUTO_COMPLETION part of syntax definition files
286
         */
285
         */
287
        ,_parseSyntaxAutoCompletionDatas: function(){
286
        ,_parseSyntaxAutoCompletionDatas: function(){
288
                //foreach syntax loaded
287
                //foreach syntax loaded
Line 321... Line 320...
321
                                                        {
320
                                                        {
322
                                                                tmp["keywords"][prefix]['datas'][j]= {
321
                                                                tmp["keywords"][prefix]['datas'][j]= {
323
                                                                        is_typing: datas["KEYWORDS"][prefix][j][0],
322
                                                                        is_typing: datas["KEYWORDS"][prefix][j][0],
324
                                                                        // if replace with is empty, replace with the is_typing value
323
                                                                        // if replace with is empty, replace with the is_typing value
325
                                                                        replace_with: datas["KEYWORDS"][prefix][j][1] ? datas["KEYWORDS"][prefix][j][1].replace('§', datas["KEYWORDS"][prefix][j][0] ) : '',
324
                                                                        replace_with: datas["KEYWORDS"][prefix][j][1] ? datas["KEYWORDS"][prefix][j][1].replace('§', datas["KEYWORDS"][prefix][j][0] ) : '',
326
                                                                        comment: datas["KEYWORDS"][prefix][j][2] ? datas["KEYWORDS"][prefix][j][2] : ''
325
                                                                        comment: datas["KEYWORDS"][prefix][j][2] ? datas["KEYWORDS"][prefix][j][2] : ''
327
                                                                };
326
                                                                };
328
                                                               
327
 
329
                                                                // the replace with shouldn't be empty
328
                                                                // the replace with shouldn't be empty
330
                                                                if( tmp["keywords"][prefix]['datas'][j]['replace_with'].length == 0 )
329
                                                                if( tmp["keywords"][prefix]['datas'][j]['replace_with'].length == 0 )
331
                                                                        tmp["keywords"][prefix]['datas'][j]['replace_with'] = tmp["keywords"][prefix]['datas'][j]['is_typing'];
330
                                                                        tmp["keywords"][prefix]['datas'][j]['replace_with'] = tmp["keywords"][prefix]['datas'][j]['is_typing'];
332
                                                               
331
 
333
                                                                // if the comment is empty, display the replace_with value
332
                                                                // if the comment is empty, display the replace_with value
334
                                                                if( tmp["keywords"][prefix]['datas'][j]['comment'].length == 0 )
333
                                                                if( tmp["keywords"][prefix]['datas'][j]['comment'].length == 0 )
335
                                                                         tmp["keywords"][prefix]['datas'][j]['comment'] = tmp["keywords"][prefix]['datas'][j]['replace_with'].replace(/{@}/g, '' );
334
                                                                         tmp["keywords"][prefix]['datas'][j]['comment'] = tmp["keywords"][prefix]['datas'][j]['replace_with'].replace(/{@}/g, '' );
336
                                                        }
335
                                                        }
337
                                                               
336
 
338
                                                }
337
                                                }
339
                                                tmp["max_text_length"]= datas["MAX_TEXT_LENGTH"];
338
                                                tmp["max_text_length"]= datas["MAX_TEXT_LENGTH"];
340
                                                parent.editAreaLoader.syntax[lang]['autocompletion'][i] = tmp;
339
                                                parent.editAreaLoader.syntax[lang]['autocompletion'][i] = tmp;
341
                                        }
340
                                        }
342
                                }
341
                                }
343
                        }
342
                        }
344
                }
343
                }
345
        }
344
        }
346
       
345
 
347
        ,_checkLetter: function(){
346
        ,_checkLetter: function(){
348
                // check that syntax hasn't changed
347
                // check that syntax hasn't changed
349
                if( this.curr_syntax_str != editArea.settings['syntax'] )
348
                if( this.curr_syntax_str != editArea.settings['syntax'] )
350
                {
349
                {
351
                        if( !parent.editAreaLoader.syntax[editArea.settings['syntax']]['autocompletion'] )
350
                        if( !parent.editAreaLoader.syntax[editArea.settings['syntax']]['autocompletion'] )
352
                                this._parseSyntaxAutoCompletionDatas();
351
                                this._parseSyntaxAutoCompletionDatas();
353
                        this.curr_syntax= parent.editAreaLoader.syntax[editArea.settings['syntax']]['autocompletion'];
352
                        this.curr_syntax= parent.editAreaLoader.syntax[editArea.settings['syntax']]['autocompletion'];
354
                        this.curr_syntax_str = editArea.settings['syntax'];
353
                        this.curr_syntax_str = editArea.settings['syntax'];
355
                        //console.log( this.curr_syntax );
354
                        //console.log( this.curr_syntax );
356
                }
355
                }
357
               
356
 
358
                if( editArea.is_editable )
357
                if( editArea.is_editable )
359
                {
358
                {
360
                        time=new Date;
359
                        time=new Date;
361
                        t1= time.getTime();
360
                        t1= time.getTime();
362
                        if(editArea.isIE)
361
                        if(editArea.isIE)
363
                                editArea.getIESelection();
362
                                editArea.getIESelection();
364
                        this.selectIndex        = -1;
363
                        this.selectIndex        = -1;
365
                        start=editArea.textarea.selectionStart;
364
                        start=editArea.textarea.selectionStart;
366
                        var str = editArea.textarea.value;
365
                        var str = editArea.textarea.value;
367
                        var results= [];
366
                        var results= [];
368
                       
367
 
369
                       
368
 
370
                        for(var i in this.curr_syntax)
369
                        for(var i in this.curr_syntax)
371
                        {
370
                        {
372
                                var last_chars  = str.substring(Math.max(0, start-this.curr_syntax[i]["max_text_length"]), start);
371
                                var last_chars  = str.substring(Math.max(0, start-this.curr_syntax[i]["max_text_length"]), start);
373
                                var matchNextletter     = str.substring(start, start+1).match( this.curr_syntax[i]["match_next_letter"]);
372
                                var matchNextletter     = str.substring(start, start+1).match( this.curr_syntax[i]["match_next_letter"]);
374
                                // if not writting in the middle of a word or if forcing display
373
                                // if not writting in the middle of a word or if forcing display
375
                                if( matchNextletter || this.forceDisplay )
374
                                if( matchNextletter || this.forceDisplay )
376
                                {
375
                                {
377
                                        // check if the last chars match a separator
376
                                        // check if the last chars match a separator
378
                                        var match_prefix_separator = last_chars.match(this.curr_syntax[i]["match_prefix_separator"]);
377
                                        var match_prefix_separator = last_chars.match(this.curr_syntax[i]["match_prefix_separator"]);
379
                       
378
 
380
                                        // check if it match a possible word
379
                                        // check if it match a possible word
381
                                        var match_word= last_chars.match(this.curr_syntax[i]["match_word"]);
380
                                        var match_word= last_chars.match(this.curr_syntax[i]["match_word"]);
382
                                       
381
 
383
                                        //console.log( match_word );
382
                                        //console.log( match_word );
384
                                        if( match_word )
383
                                        if( match_word )
385
                                        {
384
                                        {
386
                                                var begin_word= match_word[1];
385
                                                var begin_word= match_word[1];
387
                                                var match_curr_word= new RegExp("^"+ parent.editAreaLoader.get_escaped_regexp( begin_word ), this.curr_syntax[i]["modifiers"]);
386
                                                var match_curr_word= new RegExp("^"+ parent.editAreaLoader.get_escaped_regexp( begin_word ), this.curr_syntax[i]["modifiers"]);
Line 390... Line 389...
390
                                                {
389
                                                {
391
                                                //      parent.console.log( this.curr_syntax[i]["keywords"][prefix] );
390
                                                //      parent.console.log( this.curr_syntax[i]["keywords"][prefix] );
392
                                                        for(var j=0; j<this.curr_syntax[i]["keywords"][prefix]['datas'].length; j++)
391
                                                        for(var j=0; j<this.curr_syntax[i]["keywords"][prefix]['datas'].length; j++)
393
                                                        {
392
                                                        {
394
                                                //              parent.console.log( this.curr_syntax[i]["keywords"][prefix]['datas'][j]['is_typing'] );
393
                                                //              parent.console.log( this.curr_syntax[i]["keywords"][prefix]['datas'][j]['is_typing'] );
395
                                                                // the key word match or force display 
394
                                                                // the key word match or force display
396
                                                                if( this.curr_syntax[i]["keywords"][prefix]['datas'][j]['is_typing'].match(match_curr_word) )
395
                                                                if( this.curr_syntax[i]["keywords"][prefix]['datas'][j]['is_typing'].match(match_curr_word) )
397
                                                                {
396
                                                                {
398
                                                        //              parent.console.log('match');
397
                                                        //              parent.console.log('match');
399
                                                                        hasMatch = false;
398
                                                                        hasMatch = false;
400
                                                                        var before = last_chars.substr( 0, last_chars.length - begin_word.length );
399
                                                                        var before = last_chars.substr( 0, last_chars.length - begin_word.length );
401
                                                                       
400
 
402
                                                                        // no prefix to match => it's valid
401
                                                                        // no prefix to match => it's valid
403
                                                                        if( !match_prefix_separator && this.curr_syntax[i]["keywords"][prefix]['prefix'].length == 0 )
402
                                                                        if( !match_prefix_separator && this.curr_syntax[i]["keywords"][prefix]['prefix'].length == 0 )
404
                                                                        {
403
                                                                        {
405
                                                                                if( ! before.match( this.curr_syntax[i]["keywords"][prefix]['prefix_reg'] ) )
404
                                                                                if( ! before.match( this.curr_syntax[i]["keywords"][prefix]['prefix_reg'] ) )
406
                                                                                        hasMatch = true;
405
                                                                                        hasMatch = true;
407
                                                                        }
406
                                                                        }
408
                                                                        // we still need to check the prefix if there is one
407
                                                                        // we still need to check the prefix if there is one
409
                                                                        else if( this.curr_syntax[i]["keywords"][prefix]['prefix'].length > 0 )
408
                                                                        else if( this.curr_syntax[i]["keywords"][prefix]['prefix'].length > 0 )
410
                                                                        {
409
                                                                        {
411
                                                                                if( before.match( this.curr_syntax[i]["keywords"][prefix]['prefix_reg'] ) )
410
                                                                                if( before.match( this.curr_syntax[i]["keywords"][prefix]['prefix_reg'] ) )
412
                                                                                        hasMatch = true;
411
                                                                                        hasMatch = true;
413
                                                                        }
412
                                                                        }
414
                                                                       
413
 
415
                                                                        if( hasMatch )
414
                                                                        if( hasMatch )
416
                                                                                results[results.length]= [ this.curr_syntax[i]["keywords"][prefix], this.curr_syntax[i]["keywords"][prefix]['datas'][j] ];
415
                                                                                results[results.length]= [ this.curr_syntax[i]["keywords"][prefix], this.curr_syntax[i]["keywords"][prefix]['datas'][j] ];
417
                                                                }      
416
                                                                }
418
                                                        }
417
                                                        }
419
                                                }
418
                                                }
420
                                        }
419
                                        }
421
                                        // it doesn't match any possible word but we want to display something
420
                                        // it doesn't match any possible word but we want to display something
422
                                        // we'll display to list of all available words
421
                                        // we'll display to list of all available words
Line 436... Line 435...
436
                                                                else if( match_prefix_separator && this.curr_syntax[i]["keywords"][prefix]['prefix'].length > 0 )
435
                                                                else if( match_prefix_separator && this.curr_syntax[i]["keywords"][prefix]['prefix'].length > 0 )
437
                                                                {
436
                                                                {
438
                                                                        var before = last_chars; //.substr( 0, last_chars.length );
437
                                                                        var before = last_chars; //.substr( 0, last_chars.length );
439
                                                                        if( before.match( this.curr_syntax[i]["keywords"][prefix]['prefix_reg'] ) )
438
                                                                        if( before.match( this.curr_syntax[i]["keywords"][prefix]['prefix_reg'] ) )
440
                                                                                hasMatch = true;
439
                                                                                hasMatch = true;
441
                                                                }      
440
                                                                }
442
                                                                       
441
 
443
                                                                if( hasMatch )
442
                                                                if( hasMatch )
444
                                                                        results[results.length]= [ this.curr_syntax[i]["keywords"][prefix], this.curr_syntax[i]["keywords"][prefix]['datas'][j] ];     
443
                                                                        results[results.length]= [ this.curr_syntax[i]["keywords"][prefix], this.curr_syntax[i]["keywords"][prefix]['datas'][j] ];
445
                                                        }
444
                                                        }
446
                                                }
445
                                                }
447
                                        }
446
                                        }
448
                                }
447
                                }
449
                        }
448
                        }
450
                       
449
 
451
                        // there is only one result, and we can select it automatically
450
                        // there is only one result, and we can select it automatically
452
                        if( results.length == 1 && this.autoSelectIfOneResult )
451
                        if( results.length == 1 && this.autoSelectIfOneResult )
453
                        {
452
                        {
454
                        //      console.log( results );
453
                        //      console.log( results );
455
                                this._select( results[0][1]['replace_with'] );
454
                                this._select( results[0][1]['replace_with'] );
Line 470... Line 469...
470
                                        line+='</a></li>';
469
                                        line+='</a></li>';
471
                                        lines[lines.length]=line;
470
                                        lines[lines.length]=line;
472
                                }
471
                                }
473
                                // sort results
472
                                // sort results
474
                                this.container.innerHTML                = '<ul>'+ lines.sort().join('') +'</ul>';
473
                                this.container.innerHTML                = '<ul>'+ lines.sort().join('') +'</ul>';
475
                               
474
 
476
                                var cursor      = _$("cursor_pos");
475
                                var cursor      = _$("cursor_pos");
477
                                this.container.style.top                = ( cursor.cursor_top + editArea.lineHeight ) +"px";
476
                                this.container.style.top                = ( cursor.cursor_top + editArea.lineHeight ) +"px";
478
                                this.container.style.left               = ( cursor.cursor_left + 8 ) +"px";
477
                                this.container.style.left               = ( cursor.cursor_left + 8 ) +"px";
479
                                this._show();
478
                                this._show();
480
                        }
479
                        }
481
                               
480
 
482
                        this.autoSelectIfOneResult = false;
481
                        this.autoSelectIfOneResult = false;
483
                        time=new Date;
482
                        time=new Date;
484
                        t2= time.getTime();
483
                        t2= time.getTime();
485
               
484
 
486
                        //parent.console.log( begin_word +"\n"+ (t2-t1) +"\n"+ html );
485
                        //parent.console.log( begin_word +"\n"+ (t2-t1) +"\n"+ html );
487
                }
486
                }
488
        }
487
        }
489
};
488
};
490
 
489