[Sciviews-commits] r49 - in komodo/SciViews-K/content: . js

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jul 16 17:49:01 CEST 2008


Author: romain
Date: 2008-07-16 17:49:01 +0200 (Wed, 16 Jul 2008)
New Revision: 49

Modified:
   komodo/SciViews-K/content/js/console.js
   komodo/SciViews-K/content/rconsole.xul
Log:
added history mechanism with [Ctrl] +[Up] and [Ctrl] + [Down]

Modified: komodo/SciViews-K/content/js/console.js
===================================================================
--- komodo/SciViews-K/content/js/console.js	2008-07-09 07:18:50 UTC (rev 48)
+++ komodo/SciViews-K/content/js/console.js	2008-07-16 15:49:01 UTC (rev 49)
@@ -11,18 +11,48 @@
 
 sv.r.console.handleConsoleKeyPress = function(e){
   
-  if( e.keyCode == 38 && e.ctrlKey ){ // [ctrl] + [up]: cycle history
-    return(0);
+  // cycle history
+  if( e.ctrlKey && ( e.keyCode == 38 || e.keyCode == 40) ){
+    // nothing is in the history
+    if( sv.r.console.history.length == 0 ){
+      return( 0 );
+    }
+    
+    var rx = sv.r.console.getHistoryRegex() ;
+    var loop = function(i, rx){
+      var cmd = sv.r.console.history[ i ];
+      if( !rx || rx.test( cmd ) ){
+        sv.r.console.setConsoleContent( cmd );
+        sv.r.console.historyIndex = i ;
+        return( true ) ;
+      }
+      return(false) ;
+    }
+    
+    if( e.keyCode == 38 ){ 
+      // [ctrl] + [up]: cycle up history
+      for( var i=sv.r.console.historyIndex-1; i>=0; i--){
+        if( loop( i, rx) ) return(0) ;
+      }
+      for( var i=sv.r.console.history.length-1; i>=sv.r.console.historyIndex; i--){
+        if( loop( i, rx) ) return(0) ;
+      }
+    } else{
+      // [ctrl] + [down]: cycle down history
+      for( var i=sv.r.console.historyIndex+1; i<sv.r.console.history.length; i++){
+        if( loop( i, rx) ) return(0) ;
+      }
+      for( var i=0; i<=sv.r.console.historyIndex; i++){
+        if( loop( i, rx) ) return(0) ;
+      }
+    }
+    return(0) ;  
+    
   }
   
-  if( e.keyCode == 40 && e.ctrlKey ){ // [ctrl] + [down]: cycle history
-    return(0);    
-  }
-  
   if( e.keyCode == 13){ // [enter] pressed : submit to R
     sv.r.console.setCurrentCommand (sv.r.console.getConsoleContent() ) ;
     sv.r.console.parse() ;
-    
     return(0); 
   }
   
@@ -50,6 +80,7 @@
 }
 
 // function to run R code in the console
+// TODO: modify this using the context in the call to evalCallback
 sv.r.console.run = function(cmd){
   sv.r.console.setCurrentCommand( cmd );
   sv.r.console.parse() ;
@@ -97,10 +128,22 @@
 // TODO: use something else for the history, the R history, a file, mozStorage, ... ?
 // TODO: make the history persistant
 sv.r.console.history = [];
+sv.r.console.historyIndex = 0 ; 
 sv.r.console.addCommandToHistory = function(cmd){
   sv.r.console.history[ sv.r.console.history.length ] = cmd ;
 }
 
+sv.r.console.getHistoryRegex = function(){
+  var txt = document.getElementById( "sciviews_rconsole_history_filter" ) ;
+  if( txt == "" ) return( false) ;
+  try{
+    var out = new RegExp( txt ) ;
+  } catch( e ){
+    return false;
+  }
+  return out;
+}
+
 sv.r.console.refreshHistory = function(){
   var his = document.getElementById("sciviews_rconsole_console_history_richlistbox");
   var cmd;
@@ -122,7 +165,8 @@
 
 // set the content of the console
 sv.r.console.setConsoleContent = function(cmd){
-  document.getElementById( "sciviews_rconsole_console_input" ).value = "" ;
+  if( !cmd ) cmd = "" ;
+  document.getElementById( "sciviews_rconsole_console_input" ).value = cmd ;
 }
 
 sv.r.console.getCompletionTypes = function(){

Modified: komodo/SciViews-K/content/rconsole.xul
===================================================================
--- komodo/SciViews-K/content/rconsole.xul	2008-07-09 07:18:50 UTC (rev 48)
+++ komodo/SciViews-K/content/rconsole.xul	2008-07-16 15:49:01 UTC (rev 49)
@@ -140,9 +140,9 @@
                 </hbox>  
                 <tree flex="1">
                   <treecols>
-                    <treecol primary="true" label="completion" flex="1"/>
-                    <treecol label="position" flex="1"/>
-                    <treecol label="description" flex="5"/>
+                    <treecol primary="true" label="completion" flex="1" />
+                    <treecol label="position" flex="1" />
+                    <treecol label="description" flex="6"/>
                   </treecols>
                   <treechildren id="sciviews_rconsole_completion_tree_main" /> 
                 </tree>  



More information about the Sciviews-commits mailing list