diff --git a/botanjs/src/Components/Vim/Actions/FIND.js b/botanjs/src/Components/Vim/Actions/FIND.js index 86db51d..461ddc4 100644 --- a/botanjs/src/Components/Vim/Actions/FIND.js +++ b/botanjs/src/Components/Vim/Actions/FIND.js @@ -39,7 +39,7 @@ } // The root bracket as back ref 0 - var RegEx = new RegExp( "(" + parsed + ")", "g" ); + var RegEx = new RegExp( "(" + parsed + ")", "gm" ); return RegEx; }; @@ -104,9 +104,20 @@ var FirstHit; var PrevStack = []; + var LoopGuard; while( ( r = search.exec( content ) ) !== null ) { - if( !FirstHit ) FirstHit = r.index; + if( FirstHit == undefined ) + { + FirstHit = r.index; + } + + if( LoopGuard == r.index ) + { + this.__msg = VimError( "EX2", PATTERN.slice( 1 ).join( "" ) ); + return true; + } + if( p < r.index ) { Hit = r.index; @@ -114,6 +125,7 @@ } PrevStack.push( r.index ); + LoopGuard = r.index; } if( e.kMap( "N" ) ) diff --git a/botanjs/src/Components/Vim/_this.js b/botanjs/src/Components/Vim/_this.js index d55ec63..ab26706 100644 --- a/botanjs/src/Components/Vim/_this.js +++ b/botanjs/src/Components/Vim/_this.js @@ -38,6 +38,7 @@ VIMRE_VERSION = "1.0.0b"; // EXtended Errors , "EX1": "Pattern Error( %1 )" + , "EX2": "This pattern is causing infinite loop: %1" , "TODO": "%1 is not implemented yet" , "MISSING_FEATURE": "Sorry, I thought this command wasn't useful enough to implement. Please file a feature request titled \"Implement %1\" in github if you think this is important."