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] 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 = {};