From 52e4733fcc4e2301ecc45ab2f946b33d4db04289 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:06:16 +0800 Subject: [PATCH] Some interfaces --- botanjs/src/Components/Vim/Actions/INSERT.js | 38 ++++++++++++++++++++ botanjs/src/Components/Vim/Cursor.js | 20 +++++++++++ botanjs/src/Components/Vim/StatusBar.js | 2 ++ botanjs/src/Components/Vim/VimArea.js | 25 +++++++++++-- 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 botanjs/src/Components/Vim/Actions/INSERT.js diff --git a/botanjs/src/Components/Vim/Actions/INSERT.js b/botanjs/src/Components/Vim/Actions/INSERT.js new file mode 100644 index 0000000..4757065 --- /dev/null +++ b/botanjs/src/Components/Vim/Actions/INSERT.js @@ -0,0 +1,38 @@ +(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 Mesg = __import( "Components.Vim.Message" ); + + /** @type {Components.Vim.Cursor.IAction} */ + var INSERT = function( Cursor ) + { + /** @type {Components.Vim.Cursor} */ + this.cursor = Cursor; + }; + + INSERT.prototype.dispose = function() + { + }; + + INSERT.prototype.getMessage = function() + { + var l = this.cursor.feeder.firstBuffer.cols; + var msg = Mesg( "INSERT" ); + + for( var i = msg.length; i < l; i ++ ) msg += " "; + return msg; + }; + + ns[ NS_EXPORT ]( EX_CLASS, "INSERT", INSERT ); +})(); diff --git a/botanjs/src/Components/Vim/Cursor.js b/botanjs/src/Components/Vim/Cursor.js index eba3821..cb58611 100644 --- a/botanjs/src/Components/Vim/Cursor.js +++ b/botanjs/src/Components/Vim/Cursor.js @@ -12,6 +12,8 @@ /** @type {System.Debug} */ var debug = __import( "System.Debug" ); + var Actions = __import( "Components.Vim.Actions.*" ); + var GetLine = function( buffs, l ) { /** @type {Components.Vim.LineBuffer} */ @@ -76,6 +78,9 @@ // The resulting position this.P = 0; + + /** @type {Components.Vim.IAction} */ + this.action = null; }; // Can only be 1, -1 @@ -210,6 +215,15 @@ this.updatePosition(); }; + Cursor.prototype.openInsert = function() + { + var feeder = this.feeder; + if( this.action ) this.action.dispose(); + this.action = new Actions[ "INSERT" ]; + + feeder.dispatcher.dispatchEvent( new BotanEvent( "VisualUpdate" ) ); + }; + Cursor.prototype.getLine = function() { var feeder = this.feeder; @@ -225,6 +239,12 @@ return line; }; + __readOnly( Cursor.prototype, "message", function() + { + return this.action && this.action.getMessage(); + } ); + + __readOnly( Cursor.prototype, "position", function() { return { diff --git a/botanjs/src/Components/Vim/StatusBar.js b/botanjs/src/Components/Vim/StatusBar.js index 20424c8..ecdec78 100644 --- a/botanjs/src/Components/Vim/StatusBar.js +++ b/botanjs/src/Components/Vim/StatusBar.js @@ -38,6 +38,8 @@ if( text ) { text = text(); + if( text == undefined || text === "" ) continue; + display += text.substr( 0, avail ); i = display.length - 1; } diff --git a/botanjs/src/Components/Vim/VimArea.js b/botanjs/src/Components/Vim/VimArea.js index a030595..e4d00c9 100644 --- a/botanjs/src/Components/Vim/VimArea.js +++ b/botanjs/src/Components/Vim/VimArea.js @@ -50,11 +50,13 @@ 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 - case 8: // Backspace cfeeder.cursor.moveX( -1 ); break; case 74: // j @@ -67,9 +69,24 @@ cfeeder.cursor.moveX( 1 ); break; + // Insert case 65: // a - case 1065: // 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 @@ -171,6 +188,10 @@ return mesg( cfeeder.docPos ); } ); + statusBar.stamp( 0, function(){ + return cfeeder.cursor.message; + } ); + sfeeder.init( statusBar.statusText ); var Update = function()