X-Git-Url: https://jfr.im/git/irc/quakenet/qwebirc.git/blobdiff_plain/86100f08e0277865f58c3c9aec613d398aeb69f1..09f39d2e45040e8ae0d605baa9deda6fcdccf0c0:/js/ui/tabcompleter.js diff --git a/js/ui/tabcompleter.js b/js/ui/tabcompleter.js index 606eaad..68af33e 100644 --- a/js/ui/tabcompleter.js +++ b/js/ui/tabcompleter.js @@ -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; @@ -166,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); }