@@ -13,6 +13,7 @@ var editors = require("ext/editors/editors");
1313var  code  =  require ( "ext/code/code" ) ; 
1414var  dom  =  require ( "ace/lib/dom" ) ; 
1515var  keyhandler  =  require ( "ext/language/keyhandler" ) ; 
16+ var  completeUtil  =  require ( "ext/codecomplete/complete_util" ) ; 
1617
1718var  lang  =  require ( "ace/lib/lang" ) ; 
1819var  language ; 
@@ -78,30 +79,6 @@ function isPopupVisible() {
7879    return  barCompleterCont . $ext . style . display  !==  "none" ; 
7980} 
8081
81- function  retrievePreceedingIdentifier ( text ,  pos ,  regex )  { 
82-     regex  =  regex  ||  ID_REGEX ; 
83-     var  buf  =  [ ] ; 
84-     for ( var  i  =  pos - 1 ;  i  >=  0 ;  i -- )  { 
85-         if ( regex . test ( text [ i ] ) ) 
86-             buf . push ( text [ i ] ) ; 
87-         else 
88-             break ; 
89-     } 
90-     return  buf . reverse ( ) . join ( "" ) ; 
91- } 
92- 
93- function  retrieveFollowingIdentifier ( text ,  pos ,  regex )  { 
94-     regex  =  regex  ||  ID_REGEX ; 
95-     var  buf  =  [ ] ; 
96-     for  ( var  i  =  pos ;  i  <  text . length ;  i ++ )  { 
97-         if  ( regex . test ( text [ i ] ) ) 
98-             buf . push ( text [ i ] ) ; 
99-         else 
100-             break ; 
101-     } 
102-     return  buf ; 
103- } 
104- 
10582function  isJavaScript ( )  { 
10683    return  editors . currentEditor . amlEditor . syntax  ===  "javascript" ; 
10784} 
@@ -119,7 +96,7 @@ function isHtml() {
11996function  replaceText ( editor ,  match )  { 
12097    // Replace text asynchronously in case Concorde didn't update the editor yet 
12198    setTimeout ( function ( )  { 
122-         asyncReplaceText ( editor ,  prefix ,   match ) ; 
99+         asyncReplaceText ( editor ,  match ) ; 
123100    } ,  CONCORDE_DELAY ) ; 
124101} 
125102
@@ -128,7 +105,7 @@ function asyncReplaceText(editor, match) {
128105    var  pos  =  editor . getCursorPosition ( ) ; 
129106    var  line  =  editor . getSession ( ) . getLine ( pos . row ) ; 
130107    var  doc  =  editor . getSession ( ) . getDocument ( ) ; 
131-     var  prefix  =  retrievePreceedingIdentifier ( line ,  pos . column ,  match . idRegex ) ; 
108+     var  prefix  =  completeUtil . retrievePreceedingIdentifier ( line ,  pos . column ,  match . idRegex ) ; 
132109
133110    if  ( match . replaceText  ===  "require(^^)"  &&  isJavaScript ( ) )  { 
134111        newText  =  "require(\"^^\")" ; 
@@ -148,11 +125,11 @@ function asyncReplaceText(editor, match) {
148125    var  prefixWhitespace  =  line . substring ( 0 ,  i ) ; 
149126
150127    // Remove HTML duplicate '<' completions 
151-     var  preId  =  retrievePreceedingIdentifier ( line ,  pos . column ,  match . idRegex ) ; 
128+     var  preId  =  completeUtil . retrievePreceedingIdentifier ( line ,  pos . column ,  match . idRegex ) ; 
152129    if  ( isHtml ( )  &&  line [ pos . column - preId . length - 1 ]  ===  '<'  &&  newText [ 0 ]  ===  '<' ) 
153130        newText  =  newText . substring ( 1 ) ; 
154131
155-     var  postfix  =  retrieveFollowingIdentifier ( line ,  pos . column ,  match . idRegex )  ||  "" ; 
132+     var  postfix  =  completeUtil . retrieveFollowingIdentifier ( line ,  pos . column ,  match . idRegex )  ||  "" ; 
156133
157134    // Pad the text to be inserted 
158135    var  paddedLines  =  newText . split ( "\n" ) . join ( "\n"  +  prefixWhitespace ) ; 
@@ -321,7 +298,7 @@ module.exports = {
321298                    docHead  =  match . name  +  " : "  +  _self . $guidToLongString ( match . type )  +  "</div>" ; 
322299                } 
323300            } 
324-             var  prefix  =  retrievePreceedingIdentifier ( line ,  pos . column ,  match . idRegex ) ; 
301+             var  prefix  =  completeUtil . retrievePreceedingIdentifier ( line ,  pos . column ,  match . idRegex ) ; 
325302            var  trim  =  match . meta  ? " maintrim"  : "" ; 
326303            if  ( ! isInferAvailable  ||  match . icon )  { 
327304                html  +=  '<span class="main'  +  trim  +  '"><u>'  +  prefix  +  "</u>"  +  match . name . substring ( prefix . length )  +  '</span>' ; 
@@ -550,7 +527,7 @@ module.exports = {
550527        // Remove out-of-date matches 
551528        for  ( var  i  =  0 ;  i  <  matches . length ;  i ++ )  { 
552529            idRegex  =  idRegex  ||  matches [ i ] . idRegex ; 
553-             identifier  =  retrievePreceedingIdentifier ( line ,  pos . column ,  matches [ i ] . idRegex ) ; 
530+             identifier  =  completeUtil . retrievePreceedingIdentifier ( line ,  pos . column ,  matches [ i ] . idRegex ) ; 
554531            if ( matches [ i ] . name . indexOf ( identifier )  !==  0 )  { 
555532                matches . splice ( i ,  1 ) ; 
556533                i -- ; 
@@ -562,7 +539,7 @@ module.exports = {
562539            replaceText ( editor ,  matches [ 0 ] ) ; 
563540        } 
564541        else  if  ( matches . length  >  0 )  { 
565-             identifier  =  retrievePreceedingIdentifier ( line ,  pos . column ,  idRegex ) ; 
542+             identifier  =  completeUtil . retrievePreceedingIdentifier ( line ,  pos . column ,  idRegex ) ; 
566543            this . showCompletionBox ( matches ,  identifier ) ; 
567544        } 
568545        else  { 
0 commit comments