Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard shortcuts to show empty popup #175

Open
goselito opened this issue Jan 25, 2020 · 15 comments
Open

Keyboard shortcuts to show empty popup #175

goselito opened this issue Jan 25, 2020 · 15 comments

Comments

@goselito
Copy link

Currently, you have a keyboard shortcut (Ctrl+Shift+Space) to show the popup, but it only shows if you have text selected. It would be nice to be able to show the popup without first selecting text.

I know I can just type in the address bar and press enter for a search, but the firefox native search does not have an option to open the search in a background tab

@CanisLupus
Copy link
Owner

I'm not sure about what to do about this issue, since SSS has always implied selecting text first, but there were other requests such as #64 (where you also commented) that mention using SSS as a kind of search box, which would also make sense to leverage the existing engines. Using the shortcut makes the user intention clear, even if there is nothing selected, so I think you have a point. I'll think about this. :)

@goselito
Copy link
Author

Maybe you can just implement another keyboard shortcut that will show the pop-up irrespective of whether text is selected or not. I used to make use of a similar extension in chrome that popped up in the top left corner of the browser via keyboard shortcut and also had the option to pop up when text was selected.

@CanisLupus
Copy link
Owner

I think changing the existing behaviour should be fine, since when the user presses the shortcut they should probably already want the popup. :)

@goselito
Copy link
Author

goselito commented Feb 5, 2020

This is such good news, finding that this option will be considered. If you do implement this, can you focus the text box so the user can just begin typing without first selecting the text area?

Also, it will be nice if pressing the enter key automatically performs a google search without having to click on the google icon. (or should I open this as a separate issue?)

@CanisLupus
Copy link
Owner

Hmm... those are also good suggestions! It's okay to just mention these in this issue, no need to create another, thanks.

I should be able to implement auto focus without much trouble.

I would also like enter to search Google, or rather, to search using the first search engine. The question is if we should assume the first ACTUAL engine only, since there are also icons to copy and open links that can be placed before that. That's probably it. I'll think about it.

I've not had time for updates lately but I should return soon and try to add this in the next update.

Cheers,
Daniel

@goselito
Copy link
Author

goselito commented Feb 6, 2020

Hi Daniel,

thank you for considering this. With regards to implementing a function when pressing enter, I suppose it does not really matter how you implement it (first button, first search engine) as the user will ultimately arrange their buttons and search engines in such a way as to make use of the enter key function the way it suits them.

I would suggest you implement it the way it will be easiest for you to code :-)

@CanisLupus
Copy link
Owner

Hi @goselito,

In version 3.41.0 I added auto focus on the text field when using the keyboard shortcut, and made Enter search using the first engine. However, I haven't yet been able to make the popup appear even when there's no text selected.

You might be wondering why (I also thought it would be simple but quickly found a problem). You see, SSS can register itself multiple times with a page if that page has frames, because they act independently. In those cases, pressing the shortcut requests that each frame respond to it. Since only one of the frames can have a text selection this is usually not a problem. Only the one with text will actually respond and create the popup. But without a selection, the code in both frames will try to create a popup, and you end up with two popups.

I've skipped over this for now, because the solutions I thought of are convoluted and error prone. When I work on this again and find a decent way to deal with this I'll let you know! :)

@goselito
Copy link
Author

Hi Daniel,

I am really excited to see you are making progress so quickly.

I installed the new version but found that pressing enter only works when the text field has focus, which kinda defeats the purpose as I might as well click a search icon if I am going to click on the text field.

I don't know if you can focus the text field regardless of whether or not the keyboard shortcut was used to show the popup or if the text was selected, but if the enter key will only work when the text field has focus, I suppose you will have to.

Regarding the topic of this issue, no worries... as long as you still have ideas on how to show an empty popup through a keyboard shortcut :-))

Looking forward to your next version.

@goselito
Copy link
Author

Oops, just posting this to re-open as I closed the thread by mistake.

@goselito goselito reopened this Feb 11, 2020
@CanisLupus
Copy link
Owner

Yep, for now it only works when the text field is focused because I'm not yet sure if enabling the key whenever the popup is open will cause problems for users that have the popup enabled for editable fields. ;) But this can be changed if I conclude that there are no problems.

I hope I can clean those ideas for the empty popup into a decent implementation. ;)

Cheers!

@goselito
Copy link
Author

It is not a problem now since the text field will have focus when you search for something else than what was selected and then press enter. However, once you get a solution to show an empty popup, it would defeat the purpose of using a keyboard shortcut to show an empty popup, then click the text field so you can start typing your custom search. So the goal would be to use the keyboard shortcut to show an empty popup and start typing your custom search in an already activated textbox and then press enter to search the first search engine.

Thanks for being so responsive :-))

@CanisLupus
Copy link
Owner

So the goal would be to use the keyboard shortcut to show an empty popup and start typing your custom search in an already activated textbox and then press enter to search the first search engine.

I may be missing something but if you use the keyboard shortcut it already focuses the text field and you can begin writing and press enter anytime without any clicks. What is left to implement in that particular case is the empty popup, since SSS always focuses the field when using the shortcut.

You're welcome! :)

@goselito
Copy link
Author

True, which means the only thing left to do is finding a way to show the empty pop-up.

Lol...It sounds so ridiculously simple when I say it, but I know it is not that easy.

@igorofc
Copy link
Contributor

igorofc commented Aug 14, 2020

So as explained in #149 I've been trying to implement this feature. Basically a new setting is added called "Open popup without selection" that is dependent on the "Display text box" setting being checked. It uses the same shortcut used to open the popup when the behaviour is set to 'Keyboard-only' as you guys agreed.

Behind the scenes, a 'span' tag is created with some text that is automatically selected causing the popup to show up. After that the span is removed. The text is then replaced with en empty string so it doesn't show up on the popup's text field.

The problem of multiple popups showing when the script is injected in multiple frames was - still is - challenging. The idea I had was to add an onblur event listener to the popup's text field. Because of the auto focus, every time the cursor jumps from one popup to another, the one that lost focus is hidden and just that which has the cursor on it is remains up. It's not the perfect solution but I think it gets the job done.

@CanisLupus
Copy link
Owner

CanisLupus commented Aug 15, 2020

Hi @igorofc, after my giant reply in #149 I'm out of time to say a lot here right now! :) Maybe we can deal with this one after the shortcuts? Thanks for explaining your approach in detail. :)

Unfortunately I think that creating a new element and auto selecting it will cause problems for some users, since they may have "Auto copy to clipboard" enabled or even use a different addon that triggers when there is a selection. Some webpages might also dislike, format, or even forbid the extra span (the popup itself has issues on sites with restrictive content policies, even though I try to change CSP and use Shadow DOM to avoid conflicts as much as possible).

I think a final solution to this issue would not depend on a selection, but on SSS being careful when responding to the keyboard shortcut on the different frames of a page. I honestly couldn't think of a great solution, though. Your suggestion with onblur could work, though! I've never tried that. It would depend on if the other popup is still visible for a fraction of time (would look ugly), and if it works reliably with several frames and their different "response times".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants