]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/ui/tabcompleter.js
Merge pull request #324 from retropc/master
[irc/quakenet/qwebirc.git] / js / ui / tabcompleter.js
index 3deb1a01a7ea0ef12308335f75411e3c9ca798e7..68af33e7fc9af0d395c952672844812b926021c5 100644 (file)
@@ -3,7 +3,7 @@ qwebirc.ui.TabCompleterFactory = new Class({
     this.ui = ui;
     this.reset();
   },
-  tabComplete: function(textBox) {
+  tabComplete: function(textBox, backwards) {
     var text = textBox.value;
     
     if(!$defined(this.obj)) {
@@ -54,7 +54,7 @@ qwebirc.ui.TabCompleterFactory = new Class({
         return;
     }
       
-    var r = this.obj.get();
+    var r = this.obj.get(backwards);
     if(!$defined(r))
       return;
       
@@ -94,13 +94,23 @@ qwebirc.ui.TabIterator = new Class({
      * ideally next would do the list gubbins recursively, but no JS engine currently
      * support tail recursion :(
      */
-    if(!$defined(this.list))
+    if(!$defined(this.list) || this.list.length == 0)
       return null;
     
     this.pos = this.pos + 1;
     if(this.pos >= this.list.length)
       this.pos = 0;
       
+    return this.list[this.pos];
+  },
+  prev: function() {
+    if(!$defined(this.list) || this.list.length == 0)
+      return null;
+
+    this.pos = this.pos - 1;
+    if(this.pos < 0)
+      this.pos = this.list.length - 1;
+
     return this.list[this.pos];
   }
 });
@@ -112,8 +122,8 @@ qwebirc.ui.BaseTabCompleter = new Class({
     this.suffix = suffix;
     this.iterator = new qwebirc.ui.TabIterator(client, existingNick, list);
   },
-  get: function() {
-    var n = this.iterator.next();
+  get: function(backwards) {
+    var n = backwards ? this.iterator.prev() : this.iterator.next();
     if(!$defined(n))
       return null;
       
@@ -132,7 +142,7 @@ qwebirc.ui.QueryTabCompleter = new Class({
 qwebirc.ui.QueryNickTabCompleter = new Class({
   Extends: qwebirc.ui.BaseTabCompleter,
   initialize: function(prefix, existingText, suffix, window) {
-    nick = window.name
+    var nick = window.name
     this.parent(window.client, prefix, existingText, suffix, [nick]);
   }
 });
@@ -141,19 +151,16 @@ qwebirc.ui.ChannelNameTabCompleter = new Class({
   Extends: qwebirc.ui.BaseTabCompleter,
   initialize: function(prefix, existingText, suffix, window) {
 
-    /* WTB map */
-    var l = [];
-    var wa = window.parentObject.windows[window.parentObject.getClientId(window.client)];
-    
-    for(var c in window.client.channels) {
-      var w = wa[c];
+    var wa = window.parentObject.windows.get(window.parentObject.getClientId(window.client));
+    var l = window.client.channels.map(function(c) {
+      var w = wa.get(c);
       
       /* redundant? */
       if($defined(w))
         w = w.lastSelected;
         
-      l.push([w, c]);
-    }
+      return [w, c];
+    });
     
     l.sort(function(a, b) {
       return b[0] - a[0];
@@ -169,7 +176,7 @@ qwebirc.ui.ChannelNameTabCompleter = new Class({
 qwebirc.ui.ChannelUsersTabCompleter = new Class({
   Extends: qwebirc.ui.BaseTabCompleter,
   initialize: function(prefix, existingText, suffix, window) {
-    var nc = window.client.tracker.getSortedByLastSpoke(window.name);
+    var nc = window.client.tracker.getSortedByLastSpokePrefix(window.name);
 
     this.parent(window.client, prefix, existingText, suffix, nc);
   }