]> jfr.im git - irc/quakenet/qwebirc.git/commitdiff
add shift+tab to go back through tab completion
authorChris Porter <redacted>
Tue, 26 Aug 2014 01:01:52 +0000 (02:01 +0100)
committerChris Porter <redacted>
Tue, 26 Aug 2014 01:01:52 +0000 (02:01 +0100)
fix meta hotkeys (altgr)
add alt+up/down for side tabs mode

js/ui/baseui.js
js/ui/frontends/qui.js
js/ui/tabcompleter.js

index 350debb23b55ee71b98d8c42042eb56179551009..86e1ba9b214955337fbf86bb88ff398c8593fffc 100644 (file)
@@ -239,10 +239,12 @@ qwebirc.ui.StandardUI = new Class({
   },
   __handleHotkey: function(x) {
     var success = false;
-    if(!x.alt || x.control) {
+    if(!x.alt && !x.control && !x.shift && !x.meta) {
       if((x.key == "backspace" || x.key == "/") && !this.getInputFocused(x)) {
         success = true;
       }
+    } else if(!x.alt || x.control || x.meta) {
+      /* do nothing */
     } else if(x.key == "a" || x.key == "A") {
       var highestNum = 0;
       var highestIndex = -1;
@@ -257,7 +259,7 @@ qwebirc.ui.StandardUI = new Class({
       }
       if(highestIndex > -1)
         this.selectWindow(this.windowArray[highestIndex]);
-    } else if(x.key >= '0' && x.key <= '9') {
+    } else if((x.key >= '0' && x.key <= '9') && !x.shift) {
       success = true;
       
       number = x.key - '0';
@@ -270,13 +272,14 @@ qwebirc.ui.StandardUI = new Class({
         return;
         
       this.selectWindow(this.windowArray[number]);
-    } else if(x.key == "left") {
+    } else if((x.key == "left" || x.key == "up") && !x.shift) {
       this.prevWindow();
       success = true;
-    } else if(x.key == "right") {
+    } else if((x.key == "right" || x.key == "down") && !x.shift) {
       this.nextWindow();
       success = true;
     }
+
     if(success) {
       new Event(x).stop();
       x.preventDefault();
@@ -367,8 +370,8 @@ qwebirc.ui.StandardUI = new Class({
 
     return null;
   },
-  tabComplete: function(element) {
-    this.tabCompleter.tabComplete(element);
+  tabComplete: function(element, backwards) {
+    this.tabCompleter.tabComplete(element, backwards);
   },
   resetTabComplete: function() {
     this.tabCompleter.reset();
index d7e700dc9c4d44785df5a838f1c8e1f0bb89dafc..c3b06e246c3a8905ed537e4bf3b3b86ee274c55e 100644 (file)
@@ -189,25 +189,30 @@ qwebirc.ui.QUI = new Class({
       new Event(e).stop();
       sendInput();
     });
-    
-    inputbox.addEvent("focus", this.resetTabComplete.bind(this));
-    inputbox.addEvent("mousedown", this.resetTabComplete.bind(this));
-    
+
+    var reset = this.resetTabComplete.bind(this);
+    inputbox.addEvent("focus", reset);
+    inputbox.addEvent("mousedown", reset);
+    inputbox.addEvent("keypress", reset);
+
     inputbox.addEvent("keydown", function(e) {
       var resultfn;
       var cvalue = inputbox.value;
-      
-      if(e.key == "up") {
+
+      if(e.alt || e.control || e.meta)
+        return;
+
+      if(e.key == "up" && !e.shift) {
         resultfn = this.commandhistory.upLine;
-      } else if(e.key == "down") {
+      } else if(e.key == "down" && !e.shift) {
         resultfn = this.commandhistory.downLine;
-      } else if(e.key == "tab" && !e.altKey && !e.ctrlKey && !e.shiftKey) {
+      } else if(e.key == "tab") {
+        this.tabComplete(inputbox, e.shift);
+
         new Event(e).stop();
-        this.tabComplete(inputbox);
+        e.preventDefault();
         return;
       } else {
-        /* ideally alt and other keys wouldn't break this */
-        this.resetTabComplete();
         return;
       }
       
@@ -218,6 +223,8 @@ qwebirc.ui.QUI = new Class({
       var result = resultfn.bind(this.commandhistory)();
       
       new Event(e).stop();
+      e.preventDefault();
+
       if(!result)
         result = "";
       this.lastcvalue = result;
index 801f62bad350910a0b91b03f9d60b4c3e2fbee3d..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;