From ee26a7dcc8b637fe74c0cde9a937036c585888ba 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: Tue, 15 Mar 2016 03:38:05 +0800 Subject: [PATCH 1/4] Remove useless imports --- botanjs/src/Components/Vim/Actions/INSERT.js | 19 ++-- botanjs/src/Components/Vim/Controls.js | 91 ++++++++++++++++++++ botanjs/src/Components/Vim/Cursor.js | 12 +-- botanjs/src/Components/Vim/LineBuffer.js | 11 +-- botanjs/src/Components/Vim/LineFeeder.js | 10 +-- botanjs/src/Components/Vim/StatusBar.js | 11 +-- botanjs/src/Components/Vim/VimArea.js | 80 +---------------- botanjs/src/Components/Vim/_this.js | 11 --- 8 files changed, 106 insertions(+), 139 deletions(-) create mode 100644 botanjs/src/Components/Vim/Controls.js diff --git a/botanjs/src/Components/Vim/Actions/INSERT.js b/botanjs/src/Components/Vim/Actions/INSERT.js index 4757065..35ff9be 100644 --- a/botanjs/src/Components/Vim/Actions/INSERT.js +++ b/botanjs/src/Components/Vim/Actions/INSERT.js @@ -1,17 +1,8 @@ (function(){ var ns = __namespace( "Components.Vim.Actions" ); - /** @type {Dandelion} */ - var Dand = __import( "Dandelion" ); - /** @type {Dandelion.IDOMElement} */ - var IDOMElement = __import( "Dandelion.IDOMElement" ); - /** @type {Dandelion.IDOMObject} */ - var IDOMObject = __import( "Dandelion.IDOMObject" ); - /** @type {System.Cycle} */ - var Cycle = __import( "System.Cycle" ); /** @type {System.Debug} */ - var debug = __import( "System.Debug" ); - + var debug = __import( "System.Debug" ); var Mesg = __import( "Components.Vim.Message" ); /** @type {Components.Vim.Cursor.IAction} */ @@ -25,6 +16,14 @@ { }; + INSERT.prototype.handler = function( e ) + { + e.preventDefault(); + if( e.key.length == "1" ) + { + } + }; + INSERT.prototype.getMessage = function() { var l = this.cursor.feeder.firstBuffer.cols; diff --git a/botanjs/src/Components/Vim/Controls.js b/botanjs/src/Components/Vim/Controls.js new file mode 100644 index 0000000..5dd9dc7 --- /dev/null +++ b/botanjs/src/Components/Vim/Controls.js @@ -0,0 +1,91 @@ +(function(){ + var ns = __namespace( "Components.Vim" ); + + var debug = __import( "System.Debug" ); + + var Controls = function( sender, e ) + { + // Action Mode handled by the actions themselves + var cfeeder = sender.contentFeeder; + if( cfeeder.cursor.action ) + { + cfeeder.cursor.action.handler( e ); + return; + } + + if( e.altKey + // F2 - F12 + || ( 112 < e.keyCode && e.keyCode < 124 ) + ) return; + + e.preventDefault(); + + if( e.ctrlKey ) + { + VimComboFunc( sender, e ); + return; + } + + var kCode = e.keyCode + ( e.shiftKey ? 1000 : 0 ); + + var cfeeder = sender.contentFeeder; + var sfeeder = sender.statusFeeder; + switch( kCode ) + { + // Cursor movements + case 8: // Backspace, go back 1 char, regardless of line + break; + case 72: // h + cfeeder.cursor.moveX( -1 ); + break; + case 74: // j + cfeeder.cursor.moveY( 1 ); + break; + case 75: // k + cfeeder.cursor.moveY( -1 ); + break; + case 76: // l + cfeeder.cursor.moveX( 1 ); + break; + + // Insert + case 65: // a + cfeeder.cursor.openInsert(); + break; + + case 1065: // A, append at the line end + break; + case 73: // i + break; + case 1073: // I, append before the line start, after spaces + break; + + // remove characters + case 88: // x, remove in cursor + break; + case 1088: // X, remove before cursor + break; + + case 1072: // H, First line buffer + break; + case 1076: // L, Last line buffer + break; + case 1052: // $ + cfeeder.cursor.lineEnd(); + break; + case 1053: // % + break; + case 1054: // ^ + cfeeder.cursor.lineStart(); + break; + case 1074: // J, Join lines + break; + case 1075: // K, manual entry + break; + case 112: // F1, help + } + + }; + + ns[ NS_EXPORT ]( EX_FUNC, "Controls", Controls ); +})(); diff --git a/botanjs/src/Components/Vim/Cursor.js b/botanjs/src/Components/Vim/Cursor.js index cb58611..cdebae7 100644 --- a/botanjs/src/Components/Vim/Cursor.js +++ b/botanjs/src/Components/Vim/Cursor.js @@ -1,16 +1,8 @@ (function(){ var ns = __namespace( "Components.Vim" ); - /** @type {Dandelion} */ - var Dand = __import( "Dandelion" ); - /** @type {Dandelion.IDOMElement} */ - var IDOMElement = __import( "Dandelion.IDOMElement" ); - /** @type {Dandelion.IDOMObject} */ - var IDOMObject = __import( "Dandelion.IDOMObject" ); - /** @type {System.Cycle} */ - var Cycle = __import( "System.Cycle" ); /** @type {System.Debug} */ - var debug = __import( "System.Debug" ); + var debug = __import( "System.Debug" ); var Actions = __import( "Components.Vim.Actions.*" ); @@ -219,7 +211,7 @@ { var feeder = this.feeder; if( this.action ) this.action.dispose(); - this.action = new Actions[ "INSERT" ]; + this.action = new (Actions[ "INSERT" ])( this ); feeder.dispatcher.dispatchEvent( new BotanEvent( "VisualUpdate" ) ); }; diff --git a/botanjs/src/Components/Vim/LineBuffer.js b/botanjs/src/Components/Vim/LineBuffer.js index 51c9861..41bbb03 100644 --- a/botanjs/src/Components/Vim/LineBuffer.js +++ b/botanjs/src/Components/Vim/LineBuffer.js @@ -1,16 +1,7 @@ (function(){ var ns = __namespace( "Components.Vim" ); - /** @type {Dandelion} */ - var Dand = __import( "Dandelion" ); - /** @type {Dandelion.IDOMElement} */ - var IDOMElement = __import( "Dandelion.IDOMElement" ); - /** @type {Dandelion.IDOMObject} */ - var IDOMObject = __import( "Dandelion.IDOMObject" ); - /** @type {System.Cycle} */ - var Cycle = __import( "System.Cycle" ); - /** @type {System.Debug} */ - var debug = __import( "System.Debug" ); + var debug = __import( "System.Debug" ); var LineBuffer = function( cols, nextLineBuffer ) { diff --git a/botanjs/src/Components/Vim/LineFeeder.js b/botanjs/src/Components/Vim/LineFeeder.js index 61807a2..04842af 100644 --- a/botanjs/src/Components/Vim/LineFeeder.js +++ b/botanjs/src/Components/Vim/LineFeeder.js @@ -1,16 +1,8 @@ (function(){ var ns = __namespace( "Components.Vim" ); - /** @type {Dandelion} */ - var Dand = __import( "Dandelion" ); - /** @type {Dandelion.IDOMElement} */ - var IDOMElement = __import( "Dandelion.IDOMElement" ); - /** @type {Dandelion.IDOMObject} */ - var IDOMObject = __import( "Dandelion.IDOMObject" ); - /** @type {System.Cycle} */ - var Cycle = __import( "System.Cycle" ); /** @type {System.Debug} */ - var debug = __import( "System.Debug" ); + var debug = __import( "System.Debug" ); /** @type {Components.Vim.LineBuffer} */ var LineBuffer = ns[ NS_INVOKE ]( "LineBuffer" ); diff --git a/botanjs/src/Components/Vim/StatusBar.js b/botanjs/src/Components/Vim/StatusBar.js index ecdec78..c02f82c 100644 --- a/botanjs/src/Components/Vim/StatusBar.js +++ b/botanjs/src/Components/Vim/StatusBar.js @@ -1,16 +1,7 @@ (function(){ var ns = __namespace( "Components.Vim" ); - /** @type {Dandelion} */ - var Dand = __import( "Dandelion" ); - /** @type {Dandelion.IDOMElement} */ - var IDOMElement = __import( "Dandelion.IDOMElement" ); - /** @type {Dandelion.IDOMObject} */ - var IDOMObject = __import( "Dandelion.IDOMObject" ); - /** @type {System.Cycle} */ - var Cycle = __import( "System.Cycle" ); - /** @type {System.Debug} */ - var debug = __import( "System.Debug" ); + var debug = __import( "System.Debug" ); /** @type {Components.VimArea.LineFeeder} */ var LineFeeder = ns[ NS_INVOKE ]( "LineFeeder" ); diff --git a/botanjs/src/Components/Vim/VimArea.js b/botanjs/src/Components/Vim/VimArea.js index e4d00c9..d471f54 100644 --- a/botanjs/src/Components/Vim/VimArea.js +++ b/botanjs/src/Components/Vim/VimArea.js @@ -1,12 +1,8 @@ (function(){ var ns = __namespace( "Components.Vim" ); - /** @type {Dandelion} */ - var Dand = __import( "Dandelion" ); /** @type {Dandelion.IDOMElement} */ var IDOMElement = __import( "Dandelion.IDOMElement" ); - /** @type {Dandelion.IDOMObject} */ - var IDOMObject = __import( "Dandelion.IDOMObject" ); /** @type {System.utils.DataKey} */ var DataKey = __import( "System.utils.DataKey" ); /** @type {System.Cycle} */ @@ -19,6 +15,7 @@ /** @type {Components.Vim.StatusBar} */ var StatusBar = ns[ NS_INVOKE ]( "StatusBar" ); + var VimControls = ns[ NS_INVOKE ]( "Controls" ); var mesg = ns[ NS_INVOKE ]( "Message" ); var KeyHandler = function( sender, handler ) @@ -33,81 +30,6 @@ }; }; - var VimControls = function( sender, e ) - { - if( e.altKey - // F2 - F12 - || ( 112 < e.keyCode && e.keyCode < 124 ) - ) return; - - e.preventDefault(); - if( e.ctrlKey ) - { - VimComboFunc( sender, e ); - return; - } - - var kCode = e.keyCode + ( e.shiftKey ? 1000 : 0 ); - - var cfeeder = sender.contentFeeder; - var sfeeder = sender.statusFeeder; - switch( kCode ) - { - // Cursor movements - case 8: // Backspace, go back 1 char, regardless of line - break; - case 72: // h - cfeeder.cursor.moveX( -1 ); - break; - case 74: // j - cfeeder.cursor.moveY( 1 ); - break; - case 75: // k - cfeeder.cursor.moveY( -1 ); - break; - case 76: // l - cfeeder.cursor.moveX( 1 ); - break; - - // Insert - case 65: // a - cfeeder.cursor.openInsert(); - break; - - case 1065: // A, append at the line end - break; - case 73: // i - break; - case 1073: // I, append before the line start, after spaces - break; - - // remove characters - case 88: // x, remove in cursor - break; - case 1088: // X, remove before cursor - break; - - case 1072: // H, First line buffer - break; - case 1076: // L, Last line buffer - break; - case 1052: // $ - cfeeder.cursor.lineEnd(); - break; - case 1053: // % - break; - case 1054: // ^ - cfeeder.cursor.lineStart(); - break; - case 1074: // J, Join lines - break; - case 1075: // K, manual entry - break; - case 112: // F1, help - } - - }; - /* stage @param {Dandelion.IDOMElement} */ var VimArea = function( stage ) { diff --git a/botanjs/src/Components/Vim/_this.js b/botanjs/src/Components/Vim/_this.js index d45751f..0ed8cd0 100644 --- a/botanjs/src/Components/Vim/_this.js +++ b/botanjs/src/Components/Vim/_this.js @@ -1,17 +1,6 @@ (function(){ var ns = __namespace( "Components.Vim" ); - /** @type {Dandelion} */ - var Dand = __import( "Dandelion" ); - /** @type {Dandelion.IDOMElement} */ - var IDOMElement = __import( "Dandelion.IDOMElement" ); - /** @type {Dandelion.IDOMObject} */ - var IDOMObject = __import( "Dandelion.IDOMObject" ); - /** @type {System.Cycle} */ - var Cycle = __import( "System.Cycle" ); - /** @type {System.Debug} */ - var debug = __import( "System.Debug" ); - var messages = { "INSERT": "-- INSERT --" , "REPLACE": "-- REPLACE --" From b7c693be073317f609d297442689e1a028d0961f 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: Tue, 15 Mar 2016 05:22:37 +0800 Subject: [PATCH 2/4] externs --- botanjs/src/Components/Vim/Actions/INSERT.js | 4 +- botanjs/src/Components/Vim/Controls.js | 28 ++++++++---- botanjs/src/Components/Vim/Cursor.js | 17 ++++--- botanjs/src/Components/Vim/VimArea.js | 7 --- botanjs/src/externs/Components.Vim.Cursor.js | 43 ++++++++++++++++++ botanjs/src/externs/Components.Vim.IAction.js | 9 ++++ .../src/externs/Components.Vim.LineBuffer.js | 42 ++++++++++++++++++ .../src/externs/Components.Vim.LineFeeder.js | 44 +++++++++++++++++++ .../src/externs/Components.Vim.StatusBar.js | 7 +++ botanjs/src/externs/Components.Vim.VimArea.js | 14 ++++++ botanjs/src/externs/Components.Vim.js | 2 + 11 files changed, 193 insertions(+), 24 deletions(-) create mode 100644 botanjs/src/externs/Components.Vim.Cursor.js create mode 100644 botanjs/src/externs/Components.Vim.IAction.js create mode 100644 botanjs/src/externs/Components.Vim.LineBuffer.js create mode 100644 botanjs/src/externs/Components.Vim.LineFeeder.js create mode 100644 botanjs/src/externs/Components.Vim.StatusBar.js create mode 100644 botanjs/src/externs/Components.Vim.VimArea.js create mode 100644 botanjs/src/externs/Components.Vim.js diff --git a/botanjs/src/Components/Vim/Actions/INSERT.js b/botanjs/src/Components/Vim/Actions/INSERT.js index 35ff9be..f9fe2f3 100644 --- a/botanjs/src/Components/Vim/Actions/INSERT.js +++ b/botanjs/src/Components/Vim/Actions/INSERT.js @@ -19,9 +19,7 @@ INSERT.prototype.handler = function( e ) { e.preventDefault(); - if( e.key.length == "1" ) - { - } + var inputChar = e.key; }; INSERT.prototype.getMessage = function() diff --git a/botanjs/src/Components/Vim/Controls.js b/botanjs/src/Components/Vim/Controls.js index 5dd9dc7..33629ea 100644 --- a/botanjs/src/Components/Vim/Controls.js +++ b/botanjs/src/Components/Vim/Controls.js @@ -5,19 +5,29 @@ var Controls = function( sender, e ) { - // Action Mode handled by the actions themselves - var cfeeder = sender.contentFeeder; - if( cfeeder.cursor.action ) - { - cfeeder.cursor.action.handler( e ); - return; - } - + // Neve capture these keys if( e.altKey // F2 - F12 || ( 112 < e.keyCode && e.keyCode < 124 ) ) return; + // Action Mode handled by the actions themselves + var cfeeder = sender.contentFeeder; + if( cfeeder.cursor.action ) + { + // Esc OR Ctrl+c + if( e.keyCode == 27 || ( e.ctrlKey && e.keyCode == 67 ) ) + { + e.preventDefault(); + cfeeder.cursor.closeAction(); + } + else + { + cfeeder.cursor.action.handler( e ); + } + return; + } + e.preventDefault(); if( e.ctrlKey ) @@ -50,7 +60,7 @@ // Insert case 65: // a - cfeeder.cursor.openInsert(); + cfeeder.cursor.openAction( "INSERT" ); break; case 1065: // A, append at the line end diff --git a/botanjs/src/Components/Vim/Cursor.js b/botanjs/src/Components/Vim/Cursor.js index cdebae7..6d42ad2 100644 --- a/botanjs/src/Components/Vim/Cursor.js +++ b/botanjs/src/Components/Vim/Cursor.js @@ -71,7 +71,6 @@ // The resulting position this.P = 0; - /** @type {Components.Vim.IAction} */ this.action = null; }; @@ -207,13 +206,21 @@ this.updatePosition(); }; - Cursor.prototype.openInsert = function() + Cursor.prototype.openAction = function( name ) { - var feeder = this.feeder; if( this.action ) this.action.dispose(); - this.action = new (Actions[ "INSERT" ])( this ); + this.action = new (Actions[ name ])( this ); - feeder.dispatcher.dispatchEvent( new BotanEvent( "VisualUpdate" ) ); + this.feeder.dispatcher.dispatchEvent( new BotanEvent( "VisualUpdate" ) ); + }; + + Cursor.prototype.closeAction = function() + { + if( !this.action ) return; + this.action.dispose(); + this.action = null; + + this.feeder.dispatcher.dispatchEvent( new BotanEvent( "VisualUpdate" ) ); }; Cursor.prototype.getLine = function() diff --git a/botanjs/src/Components/Vim/VimArea.js b/botanjs/src/Components/Vim/VimArea.js index d471f54..847ca78 100644 --- a/botanjs/src/Components/Vim/VimArea.js +++ b/botanjs/src/Components/Vim/VimArea.js @@ -49,9 +49,6 @@ this.rows = element.rows; this.cols = element.cols; - this.PosX = 1; - this.PosY = 1; - this.__active = false; var _self = this; @@ -64,10 +61,6 @@ this.VisualizeVimFrame( element.value ); }; - VimArea.prototype.startInput = function( mode ) - { - }; - VimArea.prototype.select = function( sel ) { if( !this.__active ) return; diff --git a/botanjs/src/externs/Components.Vim.Cursor.js b/botanjs/src/externs/Components.Vim.Cursor.js new file mode 100644 index 0000000..050c5c6 --- /dev/null +++ b/botanjs/src/externs/Components.Vim.Cursor.js @@ -0,0 +1,43 @@ +/** @constructor */ +Components.Vim.Cursor = function(){}; + +/** @type {Components.Vim.LineFeeder} */ +Components.Vim.Cursor.feeder; +/** @type {Components.Vim.IAction} */ +Components.Vim.Cursor.action; + +/** @type Function */ +Components.Vim.Cursor.moveX; +/** @type Function */ +Components.Vim.Cursor.moveY; +/** @type Function */ +Components.Vim.Cursor.lineStart; +/** @type Function */ +Components.Vim.Cursor.lineEnd; +/** @type Function */ +Components.Vim.Cursor.updatePosition; +/** @type Function */ +Components.Vim.Cursor.openAction; +/** @type Function */ +Components.Vim.Cursor.closeAction; + +/** @type {Array} */ +Components.Vim.Cursor.lineBuffers; +/** @type Number */ +Components.Vim.Cursor.pX; +/** @type Number */ +Components.Vim.Cursor.P; +/** @type Number */ +Components.Vim.Cursor.X; +/** @type Number */ +Components.Vim.Cursor.Y; +/** @type Number */ +Components.Vim.Cursor.cols; +/** @type message */ +Components.Vim.Cursor.string; +/** @type Object */ +Components.Vim.Cursor.position; +/** @type Number */ +Components.Vim.Cursor.position.start; +/** @type Number */ +Components.Vim.Cursor.position.end; diff --git a/botanjs/src/externs/Components.Vim.IAction.js b/botanjs/src/externs/Components.Vim.IAction.js new file mode 100644 index 0000000..db82c97 --- /dev/null +++ b/botanjs/src/externs/Components.Vim.IAction.js @@ -0,0 +1,9 @@ +/** @constructor */ +Components.Vim.IAction = function(){}; + +/** @type Function */ +Components.Vim.IAction.dispose; +/** @type Function */ +Components.Vim.IAction.handler; +/** @type Function */ +Components.Vim.IAction.getMessage; diff --git a/botanjs/src/externs/Components.Vim.LineBuffer.js b/botanjs/src/externs/Components.Vim.LineBuffer.js new file mode 100644 index 0000000..58f3e71 --- /dev/null +++ b/botanjs/src/externs/Components.Vim.LineBuffer.js @@ -0,0 +1,42 @@ +/** @constructor */ +Components.Vim.LineBuffer = function(){}; + +/** @type {Components.Vim.LineBuffer} */ +Components.Vim.LineBuffer.next; +/** @type {Components.Vim.LineBuffer} */ +Components.Vim.LineBuffer.prev; +/** @type {Components.Vim.LineBuffer} */ +Components.Vim.LineBuffer.nextLine; + +/** @type EventDispatcher */ +Components.Vim.LineBuffer.dispatcher; + +/** @type Function */ +Components.Vim.LineBuffer.softReset; +/** @type Function */ +Components.Vim.LineBuffer.pan; +/** @type Function */ +Components.Vim.LineBuffer.render; +/** @type Function */ +Components.Vim.LineBuffer.setRender; +/** @type Function */ +Components.Vim.LineBuffer.init; +/** @type Function */ +Components.Vim.LineBuffer.setWrap; + +/** @type Array */ +Components.Vim.LineBuffer.visualLines; +/** @type Boolean */ +Components.Vim.LineBuffer.placeholder; +/** @type Boolean */ +Components.Vim.LineBuffer.br; +/** @type Number */ +Components.Vim.LineBuffer.cols; +/** @type Number */ +Components.Vim.LineBuffer.lineNum; +/** @type Number */ +Components.Vim.LineBuffer.tabWidth; +/** @type Number */ +Components.Vim.LineBuffer.linesOccupied; +/** @type String */ +Components.Vim.LineBuffer.content; diff --git a/botanjs/src/externs/Components.Vim.LineFeeder.js b/botanjs/src/externs/Components.Vim.LineFeeder.js new file mode 100644 index 0000000..64fe726 --- /dev/null +++ b/botanjs/src/externs/Components.Vim.LineFeeder.js @@ -0,0 +1,44 @@ +/** @constructor */ +Components.Vim.LineFeeder = function(){}; + +/** @type {Components.Vim.Cursor} */ +Components.Vim.LineFeeder.cursor; +/** @type {Components.Vim.LineBuffer} */ +Components.Vim.LineFeeder.firstBuffer; +/** @type {Components.Vim.LineBuffer} */ +Components.Vim.LineFeeder.lastBuffer; + +/** @type EventDispatcher */ +Components.Vim.LineFeeder.dispatcher; + +/** @type Function */ +Components.Vim.LineFeeder.softReset; +/** @type Function */ +Components.Vim.LineFeeder.pan; +/** @type Function */ +Components.Vim.LineFeeder.render; +/** @type Function */ +Components.Vim.LineFeeder.setRender; +/** @type Function */ +Components.Vim.LineFeeder.init; +/** @type Function */ +Components.Vim.LineFeeder.setWrap; + +/** @type {Array} */ +Components.Vim.LineFeeder.lineBuffers; +/** @type Boolean */ +Components.Vim.LineFeeder.EOF; +/** @type Number */ +Components.Vim.LineFeeder.panX; +/** @type Number */ +Components.Vim.LineFeeder.panY; +/** @type Number */ +Components.Vim.LineFeeder.moreAt; +/** @type Number */ +Components.Vim.LineFeeder.linesOccupied; +/** @type String */ +Components.Vim.LineFeeder.docPos; +/** @type String */ +Components.Vim.LineFeeder.lineStat; +/** @type {String} */ +Components.Vim.LineFeeder.content; diff --git a/botanjs/src/externs/Components.Vim.StatusBar.js b/botanjs/src/externs/Components.Vim.StatusBar.js new file mode 100644 index 0000000..356c980 --- /dev/null +++ b/botanjs/src/externs/Components.Vim.StatusBar.js @@ -0,0 +1,7 @@ +/** @constructor */ +Components.Vim.StatusBar = function(){}; + +/** @type Function */ +Components.Vim.StatusBar.stamp; +/** @type String */ +Components.Vim.StatusBar.statusText; diff --git a/botanjs/src/externs/Components.Vim.VimArea.js b/botanjs/src/externs/Components.Vim.VimArea.js new file mode 100644 index 0000000..e71c020 --- /dev/null +++ b/botanjs/src/externs/Components.Vim.VimArea.js @@ -0,0 +1,14 @@ +/** @constructor */ +Components.Vim.VimArea = function(){}; + +/** @type {Components.Vim.LineFeeder} */ +Components.Vim.VimArea.contentFeeder; +/** @type {Components.Vim.LineFeeder} */ +Components.Vim.VimArea.statusFeeder; +/** @type {Components.Vim.StatusBar} */ +Components.Vim.VimArea.statusBar; + +/** @type {Number} */ +Components.Vim.VimArea.rows; +/** @type {Number} */ +Components.Vim.VimArea.cols; diff --git a/botanjs/src/externs/Components.Vim.js b/botanjs/src/externs/Components.Vim.js new file mode 100644 index 0000000..2822cd0 --- /dev/null +++ b/botanjs/src/externs/Components.Vim.js @@ -0,0 +1,2 @@ +/** @object */ +Components.Vim = {}; From 030a0f3c1a81dde13d2800ffcdaa4dc4369f8248 Mon Sep 17 00:00:00 2001 From: tgckpg Date: Tue, 15 Mar 2016 06:12:31 +0800 Subject: [PATCH 3/4] Create README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..8a8ca0c --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# BotanJS-vim +A textarea powered by vim controls in BotanJS + +Visit the demo over [here](https://tgckpg.github.io/BotanJS-vim) From 8bc4db72831bf35e59ca918638a5db50994b7a4e 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: Wed, 16 Mar 2016 00:11:39 +0800 Subject: [PATCH 4/4] partial insert support --- botanjs/src/Components/Vim/Actions/INSERT.js | 47 ++++++++++++++++++- botanjs/src/Components/Vim/Cursor.js | 22 ++++++++- botanjs/src/Components/Vim/LineBuffer.js | 5 +- botanjs/src/Components/Vim/LineFeeder.js | 19 ++++---- botanjs/src/externs/Components.Vim.Cursor.js | 2 + .../src/externs/Components.Vim.LineFeeder.js | 2 + 6 files changed, 83 insertions(+), 14 deletions(-) diff --git a/botanjs/src/Components/Vim/Actions/INSERT.js b/botanjs/src/Components/Vim/Actions/INSERT.js index f9fe2f3..e131c88 100644 --- a/botanjs/src/Components/Vim/Actions/INSERT.js +++ b/botanjs/src/Components/Vim/Actions/INSERT.js @@ -5,6 +5,17 @@ var debug = __import( "System.Debug" ); var Mesg = __import( "Components.Vim.Message" ); + var Translate = function( c ) + { + switch( c ) + { + case "Tab": + return "\t"; + default: + return c; + } + }; + /** @type {Components.Vim.Cursor.IAction} */ var INSERT = function( Cursor ) { @@ -19,7 +30,41 @@ INSERT.prototype.handler = function( e ) { e.preventDefault(); - var inputChar = e.key; + var inputChar = Translate( e.key ); + + if( inputChar.length != 1 ) return; + + var cur = this.cursor; + var feeder = cur.feeder; + + var line = cur.getLine(); + var n = line.lineNum; + + var cont = feeder.content; + + var f = 0; + if( 0 < n ) + { + f = cont.indexOf( "\n" ); + for( i = 1; f != -1 && i < n; i ++ ) + { + f = cont.indexOf( "\n", f + 1 ); + } + + if( this.cursor.feeder.wrap ) + { + // wordwrap offset + f ++; + } + } + + f += cur.aX; + + feeder.content = cont.substring( 0, f ) + inputChar + cont.substring( f ); + feeder.pan(); + feeder.dispatcher.dispatchEvent( new BotanEvent( "VisualUpdate" ) ); + + cur.moveX( 1 ); }; INSERT.prototype.getMessage = function() diff --git a/botanjs/src/Components/Vim/Cursor.js b/botanjs/src/Components/Vim/Cursor.js index 6d42ad2..b73c4ed 100644 --- a/botanjs/src/Components/Vim/Cursor.js +++ b/botanjs/src/Components/Vim/Cursor.js @@ -238,12 +238,32 @@ return line; }; + // The absX for current Line + __readOnly( Cursor.prototype, "aX", function() + { + var X = this.X; + var f = this.feeder; + + // Calculate wordwrap offset + if( f.wrap ) + { + var cols = f.firstBuffer.cols + 1; + var w = X < cols ? 0 : Math.floor( X / cols ); + + if( 0 < w ) + { + X -= w; + } + } + + return X; + } ); + __readOnly( Cursor.prototype, "message", function() { return this.action && this.action.getMessage(); } ); - __readOnly( Cursor.prototype, "position", function() { return { diff --git a/botanjs/src/Components/Vim/LineBuffer.js b/botanjs/src/Components/Vim/LineBuffer.js index 41bbb03..2eccb0d 100644 --- a/botanjs/src/Components/Vim/LineBuffer.js +++ b/botanjs/src/Components/Vim/LineBuffer.js @@ -39,9 +39,10 @@ var i = 0; var numTabs = 0; + var tabw = this.tabWidth - 1; if( wrap ) { - for( ; i < this.cols - numTabs * this.tabWidth; i ++ ) + for( ; i < this.cols - numTabs * tabw; i ++ ) { var c = content[i]; if( c === undefined ) break; @@ -78,7 +79,7 @@ numTabs ++; } - if( i < this.cols - numTabs * this.tabWidth ) + if( i < this.cols - numTabs * tabw ) { line += c; } diff --git a/botanjs/src/Components/Vim/LineFeeder.js b/botanjs/src/Components/Vim/LineFeeder.js index 04842af..059fd04 100644 --- a/botanjs/src/Components/Vim/LineFeeder.js +++ b/botanjs/src/Components/Vim/LineFeeder.js @@ -26,6 +26,8 @@ this.panX = 0; this.panY = 0; + this.wrap = true; + this.setRender(); this.cursor = new Cursor( this ); @@ -34,8 +36,6 @@ this.__clseLine = null; this.__moreAt = -1; this.__rows = rows; - - this.__wrap = true; }; Feeder.prototype.init = function( content, wrap ) @@ -43,13 +43,15 @@ this.content = content; this.setWrap( wrap ); - this.firstBuffer.Push( content, this.__wrap, 0 ); + this.firstBuffer.Push( content, this.wrap, 0 ); }; Feeder.prototype.setWrap = function( wrap ) { if( wrap == undefined ) return; - this.__wrap = wrap; + this.wrap = wrap; + + // TODO: Update }; Feeder.prototype.setRender = function( placeholder ) @@ -128,8 +130,6 @@ if( dX == undefined ) dX = 0; if( dY == undefined ) dY = 0; - if( dX == 0 && dY == 0 ) return; - var X = this.panX + dX; var Y = this.panY + dY; @@ -142,7 +142,7 @@ if( 0 < Y ) { f = this.content.indexOf( "\n" ); - for( i = 1; f != - 1 && i < Y; i ++ ) + for( i = 1; f != -1 && i < Y; i ++ ) { f = this.content.indexOf( "\n", f + 1 ); } @@ -150,7 +150,7 @@ this.firstBuffer.Push( this.content.substr( f + 1 ) - , this.__wrap, i ); + , this.wrap, i ); this.panX = X; this.panY = Y; @@ -195,8 +195,7 @@ } ); __readOnly( Feeder.prototype, "lineStat", function() { - var X = this.cursor.X; - + var X = this.cursor.aX; var line = this.cursor.getLine(); var tabStat = ""; diff --git a/botanjs/src/externs/Components.Vim.Cursor.js b/botanjs/src/externs/Components.Vim.Cursor.js index 050c5c6..4564825 100644 --- a/botanjs/src/externs/Components.Vim.Cursor.js +++ b/botanjs/src/externs/Components.Vim.Cursor.js @@ -28,6 +28,8 @@ Components.Vim.Cursor.pX; /** @type Number */ Components.Vim.Cursor.P; /** @type Number */ +Components.Vim.Cursor.aX; +/** @type Number */ Components.Vim.Cursor.X; /** @type Number */ Components.Vim.Cursor.Y; diff --git a/botanjs/src/externs/Components.Vim.LineFeeder.js b/botanjs/src/externs/Components.Vim.LineFeeder.js index 64fe726..1730d42 100644 --- a/botanjs/src/externs/Components.Vim.LineFeeder.js +++ b/botanjs/src/externs/Components.Vim.LineFeeder.js @@ -28,6 +28,8 @@ Components.Vim.LineFeeder.setWrap; Components.Vim.LineFeeder.lineBuffers; /** @type Boolean */ Components.Vim.LineFeeder.EOF; +/** @type Boolean */ +Components.Vim.LineFeeder.wrap; /** @type Number */ Components.Vim.LineFeeder.panX; /** @type Number */