From 1bb997133f552944f48b2aea3d6af333c5e39735 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sat, 11 Jul 2015 20:12:07 -0600 Subject: [PATCH] * More WIP on FSE * Fix issue with events captured in VC when setFocus() toggle --- core/horizontal_menu_view.js | 2 +- core/multi_line_edit_text_view.js | 25 +------------------------ core/view_controller.js | 8 ++++++++ mods/fse.js | 27 ++++++++++++++------------- mods/menu.json | 15 ++------------- 5 files changed, 26 insertions(+), 51 deletions(-) diff --git a/core/horizontal_menu_view.js b/core/horizontal_menu_view.js index 85aa3dc1..d908ea6e 100644 --- a/core/horizontal_menu_view.js +++ b/core/horizontal_menu_view.js @@ -27,7 +27,7 @@ function HorizontalMenuView(options) { this.getSpacer = function() { return new Array(self.itemSpacing + 1).join(' '); - } + }; this.performAutoScale = function() { if(self.autoScale.width) { diff --git a/core/multi_line_edit_text_view.js b/core/multi_line_edit_text_view.js index 0e80e7c9..a7df2f9c 100644 --- a/core/multi_line_edit_text_view.js +++ b/core/multi_line_edit_text_view.js @@ -406,9 +406,6 @@ function MultiLineEditTextView(options) { var absPos; if(self.getTextLength(index) > self.dimens.width) { - //console.log('textLen=' + self.getTextLength(index) + ' / ' + self.dimens.width + ' / ' + - // JSON.stringify(self.getAbsolutePosition(self.cursorPos.row, self.cursorPos.col))) - // // Update word wrapping and |cursorOffset| if the cursor // was within the bounds of the wrapped text @@ -423,27 +420,16 @@ function MultiLineEditTextView(options) { self.redrawRows(self.cursorPos.row, self.dimens.height); if(!_.isUndefined(cursorOffset)) { - //console.log('cursorOffset=' + cursorOffset) self.cursorBeginOfNextLine(); self.cursorPos.col += cursorOffset; self.client.term.rawWrite(ansi.right(cursorOffset)); } else { - //console.log('this path') self.moveClientCusorToCursorPos(); - /* - - self.cursorPos.row++; - self.cursorPos.col = 1; // we just added 1 char - absPos = self.getAbsolutePosition(self.cursorPos.row, self.cursorPos.col); - console.log('absPos=' + JSON.stringify(absPos)) - self.client.term.rawWrite(ansi.goto(absPos.row, absPos.col)); - */ } } else { // // We must only redraw from col -> end of current visible line // - //console.log('textLen=' + self.getTextLength(index)) absPos = self.getAbsolutePosition(self.cursorPos.row, self.cursorPos.col); self.client.term.write( ansi.hideCursor() + @@ -518,8 +504,6 @@ function MultiLineEditTextView(options) { function addWord() { word.match(new RegExp('.{0,' + width + '}', 'g')).forEach(function wrd(w) { - //console.log(word.match(new RegExp('.{0,' + (width - 1) + '}', 'g'))) - //if(results.wrapped[i].length + w.length >= width) { if(results.wrapped[i].length + w.length > width) { if(0 === i) { results.firstWrapRange = { start : wordStart, end : wordStart + w.length }; @@ -730,7 +714,6 @@ function MultiLineEditTextView(options) { } else { self.cursorPos.col = 0; } - console.log('"' + self.getVisibleText() + '"') self.moveClientCusorToCursorPos(); self.emitEditPosition(); @@ -1050,16 +1033,10 @@ MultiLineEditTextView.prototype.setFocus = function(focused) { }; MultiLineEditTextView.prototype.setText = function(text) { - //this.textLines = [ { text : '' } ]; - //this.insertRawText(''); - //text = "Tab:\r\n\tA\tB\tC\tD\tE\tF\tG\r\n reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeally long word!!!"; text = require('fs').readFileSync('/home/nuskooler/Downloads/test_text.txt', { encoding : 'utf-8'}); - this.insertRawText(text);//, 0, 0); + this.insertRawText(text); this.cursorEndOfDocument(); - console.log(this.textLines) - - }; MultiLineEditTextView.prototype.getData = function() { diff --git a/core/view_controller.js b/core/view_controller.js index d7ba71ba..8f2f26a0 100644 --- a/core/view_controller.js +++ b/core/view_controller.js @@ -210,8 +210,16 @@ ViewController.prototype.attachClientEvents = function() { return; } + var self = this; + this.client.on('key press', this.clientKeyPressHandler); + Object.keys(this.views).forEach(function vid(i) { + // remove, then add to ensure we only have one listener + self.views[i].removeListener('action', self.viewActionListener); + self.views[i].on('action', self.viewActionListener); + }); + this.attached = true; }; diff --git a/mods/fse.js b/mods/fse.js index 963f7dfc..c9ae971f 100644 --- a/mods/fse.js +++ b/mods/fse.js @@ -237,7 +237,7 @@ function FullScreenEditorModule(options) { } ], function complete(err) { - var bodyView = self.getBodyView(); + var bodyView = self.viewControllers.body.getView(1); self.updateTextEditMode(bodyView.getTextEditMode()); self.updateEditModePosition(bodyView.getEditPosition()); @@ -247,10 +247,6 @@ function FullScreenEditorModule(options) { ); }; - this.getBodyView = function() { - return self.viewControllers.body.getView(1); - }; - this.updateEditModePosition = function(pos) { if('edit' === this.editorMode) { var posView = self.viewControllers.footerEdit.getView(1); @@ -273,6 +269,7 @@ function FullScreenEditorModule(options) { } }; + /* this.displayHelp = function() { // // Replace body area with a temporary read-only MultiLineEditText @@ -305,12 +302,13 @@ function FullScreenEditorModule(options) { self.viewControllers.help.redrawAll(); }; + */ - this.displayHelp2 = function() { + this.displayHelp = function() { self.client.term.rawWrite(ansi.resetScreen()); theme.displayThemeArt( { name : self.menuConfig.config.art.help, client : self.client }, - function artDisplayed(err, artData) { + function helpDisplayed(err, artData) { self.client.waitForKeyPress(function keyPress(ch, key) { self.redrawScreen(); self.viewControllers.footerEditMenu.setFocus(true); @@ -320,7 +318,7 @@ function FullScreenEditorModule(options) { }; this.observeEditEvents = function() { - var bodyView = self.getBodyView(); + var bodyView = self.viewControllers.body.getView(1); bodyView.on('edit position', function cursorPosUpdate(pos) { self.updateEditModePosition(pos); @@ -367,14 +365,17 @@ function FullScreenEditorModule(options) { } }); }, + editModeMenuSave : function(formData, extraArgs) { + + }, + editModeMenuHelp : function(formData, extraArgs) { + self.viewControllers.footerEditMenu.setFocus(false); + self.displayHelp(); + }, editModeMenu : function(formData, extraArgs) { console.log('menu ' + formData.value['1']) - if(3 == formData.value['1']) { - console.log('Display help...') - self.viewControllers.footerEditMenu.setFocus(false); - self.displayHelp2(); - } + } }; } diff --git a/mods/menu.json b/mods/menu.json index e8490200..4237f365 100644 --- a/mods/menu.json +++ b/mods/menu.json @@ -587,7 +587,7 @@ }, { "value" : { "1" : 1 }, - "action" : "@method:editModeMenu" + "action" : "@menu:demoMain" }, { "value" : { "1" : 2 }, @@ -595,7 +595,7 @@ }, { "value" : { "1" : 3 }, - "action" : "@method:editModeMenu" + "action" : "@method:editModeMenuHelp" }, { "value" : 1, @@ -617,17 +617,6 @@ } */ } - }, - "5" : { - "ML1" : { - "mci" : { - "ML1" : { - "width" : 79, - "height" : 17, - "text" : "" // :TODO: fixme - } - } - } } } /*