Page 1 of 1

General Shift key modifier support for hotkeys

Posted: 18 Mar 2013, 19:45
by phz
Ctrl-key combinations can be defined for hotkeys via the caret (^) prefix, e.g.

Code: Select all

$hotkeys["^(38)|Ctrl-up"] = "prev_article_noscroll";

Many Shift-key combinations are covered by being able to bind [A-Z], but I wanted to bind Shift+↓ and Shift+↑ and could not see how.

I added:

Code: Select all

--- a/www/js/tt-rss.js
+++ b/www/js/tt-rss.js
@@ -578,6 +578,7 @@
 
       var hotkey = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")";
       if (ctrl_key) hotkey = "^" + hotkey;
+      else if (shift_key && keychar.search(/[A-Z]/) == -1) hotkey = "*" + hotkey;
       hotkey = hotkey_prefix ? hotkey_prefix + " " + hotkey : hotkey;
       hotkey_prefix = false;

Without the extra logic as compared to the Ctrl-line above, capital letter hotkeys will no longer work (since e.g. "H" is the same as "Shift+h", and the added line would then look for "*H", which likely doesn't exist and would collide with earlier functionality). If one wants to be able to use Ctrl+Shift-hotkeys, it could be done with some small additions.

I arbitrarily used the asterisk as identifier for Shift, so now I can add this to my plugin containing my hotkey preferences:

Code: Select all

$hotkeys['*(38)|Shift-up']   = 'prev_feed';
$hotkeys['*(40)|Shift-down'] = 'next_feed';

Not exactly nuclear science, but I might as well share, in case someone else wants this. It works for me. Not guaranteeing bug free behavior in general :-) .

I'd personally appreciate if it went into mainline so I won't need to apply the patch on package upgrades, but its usefulness and merits are for for other people to decide.

Thanks for the project! I wouldn't go back to Google Reader even if they begged me.

Re: General Shift key modifier support for hotkeys

Posted: 18 Mar 2013, 20:31
by fox
Pull request for this would be nice, because it makes sense. Especially if you changed the existing base hotkeys to the new notation.

Edit: ah it's backwards compatible. You know, maybe it shouldn't be, to prevent confusion.

Edit2: ok nvm the pull request, I'm half way through on this already. :)

Re: General Shift key modifier support for hotkeys

Posted: 18 Mar 2013, 21:00
by fox

Re: General Shift key modifier support for hotkeys

Posted: 18 Mar 2013, 23:17
by phz
Nice, thanks! Certainly seems more robust than my one-liner :-) .