CanisLupus / swift-selection-search

Swift Selection Search (SSS) is a simple Firefox add-on that lets you quickly search for some text in a page using your favorite search engines.
https://addons.mozilla.org/firefox/addon/swift-selection-search/
MIT License
213 stars 27 forks source link

moving between engines using tab/arrow keys is not working for me #232

Closed nik-gr closed 3 years ago

nik-gr commented 3 years ago

From what I have read it supposed to be possible to use arrows or arrow keys to browse search engines in the popup window but it's not happening for me. I tried with all other addons disabled but still not possible. I have the popup to be in the grid form (too many engines to use the single row one). Even when I have focus on the text field, pressing tab will get me away from the popup. Is this a bug?

CanisLupus commented 3 years ago

Hi! Although arrow keys are not supported, SSS should allow pressing Tab to select the next icon and Shift+Tab to go to the previous one. And then Enter to confirm. Does this not work?

I checked it here and both single line and grid display seem to work for me. Not sure why it's not working for you, especially since you disabled other addons. Hmm...

nik-gr commented 3 years ago

On a 2nd look just now (with addons on), I see a little different behavior when using tab and when using shift+tab in any case it gives focus either only on the 1st search engine icon or that icon and the text field before moving away from the popup window

Thank you for letting me know I didn't want to chase a nonexistent issue. I will try to trace what introduces this issue and update here

nik-gr commented 3 years ago

ok so the issue was because of an about:config setting I changed: accessibility.tabfocus = 1. When I changed it to default, pressing tab started working as expected (although at least with my configuration the dotted line around the focused box is barely noticeable)

(it's not really a very convenient way to move around engine boxes like that if there are plenty of them, I hope you'll consider adding a better navigation way in a future update, perhaps using shift+arrows when the focus is on the popup or even better and probably much easier to allow a 2-characters shortcuts for the engines - I know, its a feature request soryy...)

Thanks for this nice addon

CanisLupus commented 3 years ago

Hi nik-gr, thanks for updating me and for letting me know of that setting.

Yeah, I agree that it's not the most convenient way of selecting an engine with the keyboard. That was intended as an "extra" as part of the single key shortcuts feature.

Although there is no support for more-than-one-key shortcuts, the single key ones should work nicely to search using any of the engines, provided that they have a key assigned. Even if you open the popup with the keyboard shortcut (which focuses the text field), you can tab away from it and then press the engine's key to search.

nik-gr commented 3 years ago

H thank you for the suggestion I am aware of that feature but I do have a few dozens of search engines, (some are groups) and it's not really helpful. For example I have an engine for searching websites at alexa and I also have amazon, with 2 characters shortcuts it's easy to distinct them: 'al', 'am' or for wikipedia english 'we' and for wikipedia in greek 'wg'. With several dozens of search engines, one key shortcut is not enough. I'm guessing it won't be more than an addition of a couple of code lines for this modification, if it is so pls consider to add it in a future update (or if it is indeed as simple as I guess perhaps to give some instructions how can I and anyone else interested for that to modify it manually)

CanisLupus commented 3 years ago

I see. :) There won't be new features for the foreseeable future, but in any case, nope... this is far from adding a few lines of code. It introduces timing/ambiguity problems, for starters. And it would have to handle issues with some of the other options, like the one allowing use of the shortcuts without a popup.

nik-gr commented 3 years ago

I understand and respect that, but why timing and complexity? what I had in mind was more like: var a=0; X.onkeydown = function(e) { if(a==0) a=e.key; else { execKeyCombination(a,e.key); a=0;} }; X.onkeyup = function(e) { if (e.key == a ) a=0; };

(and perhaps an addition above to ignore TAB press events to avoid the possibility of an unexpected no zero value of 'a' when used with no popup, although even then it shouldn't create any misbehavior)

CanisLupus commented 3 years ago

These things are almost never as easy as people think. I really shouldn't discuss features since this is the kind of thing I wanted to get away from when I paused development, but I'll do it one last time and try to explain. ;)

About that code, which I believe is just a guideline and not a "final" implementation:

  1. If I understand this correctly, that code requires users to keep both keys down. 1.1. They (and I) would probably assume it would work by pressing and releasing keys in sequence. Typing works like this, as do "Alt" shortcuts in the Windows explorer/ribbon, and combo sequences in programming IDEs. 1.2. It doesn't support sequences like AA or BB.
  2. Even if it was on press down only, there are edge cases. If a user presses down a, b, and then c without releasing any of them, and then releases a or b, the c key is now invalid. Kind of a dumb example, but still an edge case.
  3. It only supports 2 keys. Whatever the solution for multiple keys that should be implemented, it should handle almost arbitrarily long sequences, otherwise I know someone would ask for sequences of 3, 4, etc.
  4. It needs to support existing users which have only single-key shortcuts.
  5. What about other meta keys like Ctrl, Alt, etc? Should probably check for them explicitly and discard.

Timing issues. What do you expect happens if the user presses a key and 5 seconds later another one? Does it count?

  1. If it does count, what if the user made a mistake in the first one? Must they now press another invalid key to "cancel" it? What keys cancel it? Maybe those keys are already used to close the popup. Or as another shortcut. Or by another setting.
  2. If it doesn't count, where do we draw the line on a "max time"? Even then, it requires a timer and possibly some global state just to keep track of this. It sounds small, but with many features it's easy to get exponential code complexity handling asynchronous behaviour like timers (i.e. now in multiple parts of the code we must remember that there is possibly a timer running and that it must be explicitly reset, even though that code is totally unrelated to it).

Complexity

  1. Apart from the possible complexity stated above (depending on the timer), now we have to deal with cases like one engine with key "a", another one with "b", and then creating another one with "ab". We need to check and warn the user with a list of all engines with shortcuts that will be overwritten, not just one (otherwise allowing these cases would result in multiple unintended searches).

  2. Since multiple sequences can start with the same letters, and since I wouldn't implement this as a 1-or-2-key-only shortcut, we should precalculate a "tree" of shortcut sequences. Technical stuff: each tree node is a "position" in one or more sequence, and edges are the possible next keys. We should restart the tree from the top on each input, so that we can have a sequence AB and, if the user presses AAB, have it still be activated. Not very hard to do, but again, a lot more code complexity.

  3. There would need to be code to convert the old shortcut format that is currently saved in the settings to the new format, which would be a sequence of keys. This code would have to exist forever, since we can't know if a user jumps from SSS version 3.40 to 3.60 directly without passing through intermediate versions (i.e. the conversion fix can't exist only in a single version of SSS). This had to be done for every new setting since version 3.00.00, but converting settings is worse.

  4. There are still other smaller things I can think of, but not too relevant (such as changes to the engines table formatting if sequences now can have multiple characters).

I hope this helps explain my thoughts. This feature is not quite on the same level as, say... adding online multiplayer to a game, which some Reddit users seem to think takes "2 weeks tops" xD, but it's much more cumbersome that it seems at first glance. It mostly always is.

Cheers! Daniel

nik-gr commented 3 years ago

Hi Daniel thank you for taking the time to reply. I totally understand what you say, I can imagine how much time consuming is to deal with all of these for something that you chose to do on your free time. It's a great addon and thank you for developed and sharing it with us. Also you are the developer, what and how you will implement/add it's your decision. Since you took the time to respond, I will try to write you my thoughts on your comments. To be honest as I explain below I still think it's just few lines of code but even if it's not you can keep them as a feedback in case you decide sometime in the future to add more features.

In my mind unlike a key of an arbitrary length which I would consider a new feature a 2-key support is more like a completion for the already existing shortcut feature, for all of us who have >20 engines a 1-key shortcut is not really a complete solution. So the functionality I had in mind, for simplicity in code yes it was as in the sample code: a 2-key shortcut where the user holds the 1st key until he presses the 2nd, no time involved. For supporting 1-key shortcuts, it can be done easily by just 'catching' them on the onkeyup event before setting 'a' back to 0 without any conflict with the 2-key ones. Yes, it's not possible to have a key of the form 'aa' but instead of not having it at all I'd consider it to be a minor compromise. Other than that, with that approach I don't see any of the problems you mention:

By removing the existent code for handling the 1-key shortcuts and adding the new one, with any small modifications like the one you mentioned (table formatting to be compatible with 2-key and perhaps also changes of how the 2-key shortcuts are stored) I don't really see any other needs.

For a key of an arbitrary length it's a different discussion. I would say not the most user friendly way but an easy implementation would be on a similar approach: by typing the shortcut (again without timing) while a control key (perhaps shift) is held down. Pressing enter or releasing the control key shall execute the shortcut, escape or space (while control key is still held) can cancel it in case of a mistyped. Such an approach, similar with the 2-key suggestion bypasses the considerations you mentioned. (more user friendly but with more work could be a solution with the addition of a hidden input field, visible with focus as a popup while shift is held down, displaying the shortcut that user is typing and in such case del could be used to delete if there is a mistyped)

It's not only the simplicity of code which is the main reason of this approach but it has the benefit that it gives more control to the user. Like what I described for alt,ctrl, I find it more welcome to leave the 'freedom' to the user to decide how to use the addon: he decides if he prefers to change some other hotkey or keep 2 actions on one shortcut, he by holding the 1st key decides how fast or slow to type the shortcut instead of a deadline that can be too short for some and too long for others.

ended up being quite long this message, sorry for that ....

CanisLupus commented 3 years ago

Hi, I read your whole message and thank you for taking the time to explain.

I had understood that your approach didn't have some of the problems I mentioned, namely timing, but I "skipped" it since on almost every program we use today, holding down non-modifier keys is very unusual and not very intuitive for users. The feature would benefit from users being able to just "write out" a few characters of an engine (such as "amz" for Amazon), so in my view it would have to allow more than 2 chars, and allow repeated chars (someone might want "ddg" for DuckDuckGo, to give an example).

I realize you mentioned yours as a simpler approach - and it is! - but simple solutions like using a single character for a shortcut mean that users will request better and more complex solutions to solve their problems (you just did ;)), so if this was reimplemented I strongly feel that it would have to be a more serious and final solution.

Inserting shortcuts with a modifier key held is more intuitive than holding down letters but I think it would still have some of the mentioned issues and add a few ones related to the browser already using some combinations.

If any of this was implemented it would require some deep thought. I guess this thread is a pretty good reminder if I ever come back to this. ;)

Cheers! Daniel

nik-gr commented 3 years ago

OK Daniel, thanks for taking the time to think about it Take care!