From 5d91d516aaf341a261129a8deb35f94e6327e968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Sat, 16 Apr 2016 19:07:13 +0800 Subject: [PATCH 1/5] Bug fix for last line shifting --- .../src/Components/Vim/Actions/SHIFT_LINES.js | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/botanjs/src/Components/Vim/Actions/SHIFT_LINES.js b/botanjs/src/Components/Vim/Actions/SHIFT_LINES.js index 1202b6c..f52ca0a 100644 --- a/botanjs/src/Components/Vim/Actions/SHIFT_LINES.js +++ b/botanjs/src/Components/Vim/Actions/SHIFT_LINES.js @@ -15,10 +15,6 @@ var occurence = __import( "System.utils.Perf.CountSubstr" ); - var REPL_BEFORE = 0; - var REPL_OFFSET = 1; - var REPL_LENGTH = 2; - /** @type {Components.Vim.IAction} * Cursor @param {Components.Vim.Cursor} * e @param {Components.Vim.ActionEvent} @@ -261,7 +257,15 @@ if( end < j ) break; - var line = c.substring( 1 < i ? i : i - 1, c.indexOf( "\n", i ) ); + var line = c.indexOf( "\n", i ); + if( ~line ) + { + line = c.substring( 1 < i ? i : i - 1, line ); + } + else + { + line = c.substring( 1 < i ? i : i - 1 ); + } if( 1 < i ) { @@ -291,7 +295,11 @@ if( !~"\t ".indexOf( line[ sj ] ) ) break; } } - else if( startC != "\t" ) break; + else if( startC == "\t" ) + { + sj ++; + } + else break; } indentedLine = line.substring( sj ); @@ -305,7 +313,9 @@ } var nPos = feeder.content.length; - feeder.content += "\n" + c.substring( i ) + "\n"; + feeder.content += "\n"; + + if( ~i ) feeder.content += c.substring( i ) + "\n"; feeder.pan(); cur.moveTo( nPos ); From 0413e943ae8cc944e39c5dec7f094e4eda0dfb46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Sat, 16 Apr 2016 19:20:14 +0800 Subject: [PATCH 2/5] Enter act as j --- botanjs/src/Components/Vim/Controls.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/botanjs/src/Components/Vim/Controls.js b/botanjs/src/Components/Vim/Controls.js index 1173343..4f982d6 100644 --- a/botanjs/src/Components/Vim/Controls.js +++ b/botanjs/src/Components/Vim/Controls.js @@ -415,6 +415,7 @@ case H: this.__cMoveX( -1 ); break; // Left case L: this.__cMoveX( 1 ); break; // Right case K: this.__cMoveY( -1 ); break; // Up + case ENTER: case J: this.__cMoveY( 1 ); break; // Down case CTRL + F: // Page Down @@ -650,6 +651,7 @@ this.__divedCCmd.dispose(); this.__cMovement = false; this.__divedCCmd = null; + return; } if( e.canceled ) return; From 450a7d578cebbeecf405b9754344277b30549ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Sat, 16 Apr 2016 21:50:16 +0800 Subject: [PATCH 3/5] Polyfilling KeyboardEvent.key for Chrome < 51 Fixed mod commands overriding INSERT action --- botanjs/src/Components/Vim/Controls.js | 71 ++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 5 deletions(-) diff --git a/botanjs/src/Components/Vim/Controls.js b/botanjs/src/Components/Vim/Controls.js index 4f982d6..cb56006 100644 --- a/botanjs/src/Components/Vim/Controls.js +++ b/botanjs/src/Components/Vim/Controls.js @@ -21,13 +21,16 @@ var TAB = 9; var ENTER = 13; var DELETE = 46; + var SPACE = 32; var UP = 38; var DOWN = 40; var LEFT = 37; var RIGHT = 39; var _0 = 48; var _1 = 49; var _2 = 50; var _3 = 51; var _4 = 52; var _5 = 53; var _6 = 54; var _7 = 55; var _8 = 56; var _9 = 57; - var SEMI_COLON = 59; + var SEMI_COLON = 59; var GECKO_SEMI_COLON = 186; + + var EQUAL = 61; var GECKO_EQUAL = 187; var A = 65; var B = 66; var C = 67; var D = 68; var E = 69; var F = 70; var G = 71; var H = 72; var I = 73; var J = 74; @@ -44,6 +47,7 @@ var F6 = 117; var F7 = 118; var F8 = 119; var F9 = 120; var F10 = 121; var F11 = 122; var F12 = 123; + var DASH = 173; var GECKO_DASH = 189; var COMMA = 188; var FULLSTOP = 190; var SLASH = 191; var BACK_SLASH = 220; @@ -139,6 +143,59 @@ return __maps[ str ] = kCode; }; + // Polyfill for Chrome < 51 + var RMap = function( kCode ) + { + switch( kCode ) + { + case SPACE: return " "; + case A: return "a"; case B: return "b"; case C: return "c"; case D: return "d"; + case E: return "e"; case F: return "f"; case G: return "g"; case H: return "h"; + case I: return "i"; case J: return "j"; case K: return "k"; case L: return "l"; + case M: return "m"; case N: return "n"; case O: return "o"; case P: return "p"; + case Q: return "q"; case R: return "r"; case S: return "s"; case T: return "t"; + case U: return "u"; case V: return "v"; case W: return "w"; case X: return "x"; + case Y: return "y"; case Z: return "z"; + case _1: return "1"; case _2: return "2"; case _3: return "3"; + case _4: return "4"; case _5: return "5"; case _6: return "6"; case _7: return "7"; + case _8: return "8"; case _9: return "9"; case _0: return "0"; + + case S_BRACKET_L: return "["; case S_BRACKET_R: return "]"; + case SEMI_COLON: case GECKO_SEMI_COLON: return ";"; + case QUOTE: return "'"; case COMMA: return ","; + case FULLSTOP: return "."; case SLASH: return "/"; case BACK_SLASH: return "\\"; + case DASH: case GECKO_DASH: return "-"; case EQUAL: case GECKO_EQUAL: return "="; + + case SHIFT + _1: return "!"; case SHIFT + _2: return "@"; case SHIFT + _3: return "#"; + case SHIFT + _4: return "$"; case SHIFT + _5: return "%"; case SHIFT + _6: return "^"; + case SHIFT + _7: return "&"; case SHIFT + _8: return "*"; case SHIFT + _9: return "("; + case SHIFT + _0: return ")"; + + case SHIFT + S_BRACKET_L: return "{"; case SHIFT + S_BRACKET_R: return "}"; + case SHIFT + SEMI_COLON: case SHIFT + GECKO_SEMI_COLON: return ":"; + case SHIFT + QUOTE: return "\""; + case SHIFT + COMMA: return "<"; case SHIFT + FULLSTOP: return ">"; + case SHIFT + SLASH: return "?"; case SHIFT + BACK_SLASH: return "|"; + case SHIFT + DASH: case SHIFT + GECKO_DASH: return "_"; + case SHIFT + EQUAL: case SHIFT + GECKO_EQUAL: return "+"; + + case SHIFT + A: return "A"; case SHIFT + B: return "B"; case SHIFT + C: return "C"; + case SHIFT + D: return "D"; case SHIFT + E: return "E"; case SHIFT + F: return "F"; + case SHIFT + G: return "G"; case SHIFT + H: return "H"; case SHIFT + I: return "I"; + case SHIFT + J: return "J"; case SHIFT + K: return "K"; case SHIFT + L: return "L"; + case SHIFT + M: return "M"; case SHIFT + N: return "N"; case SHIFT + O: return "O"; + case SHIFT + P: return "P"; case SHIFT + Q: return "Q"; case SHIFT + R: return "R"; + case SHIFT + S: return "S"; case SHIFT + T: return "T"; case SHIFT + U: return "U"; + case SHIFT + V: return "V"; case SHIFT + W: return "W"; case SHIFT + X: return "X"; + case SHIFT + Y: return "Y"; case SHIFT + Z: return "Z"; + case ESC: return "Escape"; case BACKSPACE: return "Backspace"; case DELETE: return "Delete"; + case SHIFT: return "Shift"; case ALT: return "Alt"; case CTRL: return "Control"; + case ENTER: return "Enter"; case TAB: return "Tab"; + } + + return "?"; + }; + var Controls = function( vimArea ) { /** @type {Components.Vim.VimArea} */ @@ -277,6 +334,7 @@ break; case SHIFT + SEMI_COLON: // ":" Command line + case SHIFT + GECKO_SEMI_COLON: this.__divedCCmd = new ExCommand( ccur, ":" ); this.__divedCCmd.handler( e ); break; @@ -657,12 +715,15 @@ if( e.canceled ) return; } - this.__modCommand( e ); - if( e.canceled ) return; - var cfeeder = this.__cfeeder; var ccur = this.__ccur; + if( !ccur.action || ccur.action.allowMovement ) + { + this.__modCommand( e ); + if( e.canceled ) return; + } + var kCode = e.keyCode; // Action commands are handled by the actions themselves @@ -731,7 +792,7 @@ + ( e.altKey ? ALT : 0 ); this.__modKeys = c == KEY_SHIFT || c == KEY_CTRL || c == KEY_ALT; - this.__key = e.key; + this.__key = e.key || RMap( this.__kCode ); } this.__count = 1; From 3c2cb66c8fadcfc644c56ca0c049e5633790d146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Sat, 16 Apr 2016 22:33:02 +0800 Subject: [PATCH 4/5] Bug fix for count movement --- .../src/Components/Vim/Actions/SHIFT_LINES.js | 22 +++++++++++++++---- botanjs/src/Components/Vim/Controls.js | 17 +++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/botanjs/src/Components/Vim/Actions/SHIFT_LINES.js b/botanjs/src/Components/Vim/Actions/SHIFT_LINES.js index f52ca0a..0e83a39 100644 --- a/botanjs/src/Components/Vim/Actions/SHIFT_LINES.js +++ b/botanjs/src/Components/Vim/Actions/SHIFT_LINES.js @@ -28,8 +28,8 @@ this.__slineNum = Cursor.getLine().lineNum; - this.__lines = e.count; - debug.Info( "Open shift: " + this.__lines + " line(s) below the cursor" ); + this.__lines = e.count - 1; + debug.Info( "Open shift: " + this.__lines + " line(s) from the cursor" ); this.__direction = e.kMap( ">" ) ? 1 : -1; debug.Info( "Direction is: " + ( this.__direction == 1 ? ">" : "<" ) ); @@ -62,7 +62,7 @@ if( 1 < e.count ) { - nline += e.count; + nline += ( e.count - 1 ); } // default: >>, <<, >l, Date: Sun, 17 Apr 2016 17:18:55 +0800 Subject: [PATCH 5/5] Bug fix UNDO / REDO error for indent chopping --- botanjs/src/Components/Vim/Actions/INSERT.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/botanjs/src/Components/Vim/Actions/INSERT.js b/botanjs/src/Components/Vim/Actions/INSERT.js index c35c167..08310ea 100644 --- a/botanjs/src/Components/Vim/Actions/INSERT.js +++ b/botanjs/src/Components/Vim/Actions/INSERT.js @@ -37,6 +37,7 @@ this.__stator = new Stator( Cursor ); this.__minReach = 0; this.__insertLen = 0; + this.__chopIndent = false; // Initialize this stack this.__rec( "", true ); @@ -52,6 +53,7 @@ INSERT.prototype.dispose = function() { + if( this.__chopIndent ) this.__realizeIndent(); if( this.__cancelIndent() ) { this.__cursor.feeder.pan(); @@ -175,6 +177,8 @@ var f = cur.aPos; + var chopIndent = feeder.content[ f ] != "\n"; + feeder.content = feeder.content.substring( 0, f ) + inputChar @@ -187,6 +191,7 @@ cur.moveY( 1 ); cur.lineStart(); this.__autoIndent( e ); + this.__chopIndent = chopIndent; } else { @@ -218,6 +223,7 @@ INSERT.prototype.__autoIndent = function( e ) { + var oInd = this.__phantomIndent; var carried = this.__cancelIndent(); var cur = this.__cursor; @@ -237,7 +243,7 @@ line = feeder.content.substring( i + 1, j - 1 ); } - var inDel = ""; + var inDel = carried ? oInd[ IN_DEL ] : ""; // Indent removed for( var ir = f; "\t ".indexOf( feeder.content[ ir ] ) != -1; ir ++ ) {