diff --git a/botanjs/src/Components/Vim/Actions/DELETE.js b/botanjs/src/Components/Vim/Actions/DELETE.js index 10a09c9..86922c1 100644 --- a/botanjs/src/Components/Vim/Actions/DELETE.js +++ b/botanjs/src/Components/Vim/Actions/DELETE.js @@ -45,6 +45,13 @@ var cur = this.__cursor; var feeder = cur.feeder; + // Do nothing if content is considered empty + if( feeder.firstBuffer.next.placeholder && feeder.content.length < 2 ) + { + debug.Info( "Content is empty" ); + return true; + } + var Triggered = false; if( sp == undefined ) @@ -134,7 +141,8 @@ } } - var c = feeder.content; + // last "\n" padding + var c = feeder.content.slice( 0, -1 ); var s = sp; var e = cur.aPos; @@ -151,6 +159,7 @@ this.__nline = occurence( removed, "\n" ); feeder.content = c.substring( 0, s ) + c.substring( e + 1 ); + if( feeder.content === "" ) feeder.content = "\n"; // Try to keep the original panning if possible feeder.pan( undefined diff --git a/botanjs/src/Components/Vim/Actions/INSERT.js b/botanjs/src/Components/Vim/Actions/INSERT.js index b37562d..ed9ebd8 100644 --- a/botanjs/src/Components/Vim/Actions/INSERT.js +++ b/botanjs/src/Components/Vim/Actions/INSERT.js @@ -110,9 +110,7 @@ var oY = feeder.panY + cur.Y; if( cur.X == 0 && feeder.panY == 0 && cur.Y == 0 ) return; - cur.moveX( -1, true, true ); - - var f = cur.aPos; + var f = cur.aPos - 1; if( this.__punch <= this.__minReach ) { @@ -123,6 +121,10 @@ feeder.content.substring( 0, f ) + feeder.content.substring( f + 1 ); + feeder.pan(); + + cur.moveX( -1, true, true ); + if( 0 < this.__insertLen ) this.__insertLen --; this.__punch --; } @@ -135,10 +137,11 @@ feeder.content = feeder.content.substring( 0, f ) + feeder.content.substring( f + 1 ); + + feeder.pan(); } else return; - feeder.pan(); feeder.dispatcher.dispatchEvent( new BotanEvent( "VisualUpdate" ) ); }; diff --git a/botanjs/src/Components/Vim/Cursor.js b/botanjs/src/Components/Vim/Cursor.js index 0fddee3..e9b6d13 100644 --- a/botanjs/src/Components/Vim/Cursor.js +++ b/botanjs/src/Components/Vim/Cursor.js @@ -217,7 +217,7 @@ if( boundary ) { - x = 0 < d ? lineEnd : 0; + x = 0 < x ? lineEnd : 0; } else if( c == "\n" ) {