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

Allowing to activate a link directly when it gets a search hit #131

Closed
lingnand opened this issue Oct 22, 2014 · 9 comments
Closed

Allowing to activate a link directly when it gets a search hit #131

lingnand opened this issue Oct 22, 2014 · 9 comments

Comments

@lingnand
Copy link

Back in the day of vimperator there was one feature I used from day to day. I will search for some string on the page, hit n or N to get reach the link I want, and hit <Enter> to activate it directly. With vimb I have to hit f and type the number for the link. It's no big deal but it would be nice if we can add this feature.

@fanglingsu
Copy link
Owner

I don't know this feature.

  1. Does vimperator use the normal search for that feature started by / or ?? If I search for 'foo' and there is a link with text 'foo' I use n or N to highlight this search match. If I hit <Enter> the link, containing the matching text is fired.
    This wouldn't be easy to implement in vimb, because search and hinting are totally different mechanisms.
  2. Or is this a type of hinting?

@lingnand
Copy link
Author

  1. Yes, it does. Consider a link like this:

    A long sentence containing foo.

    In vimperator you can search for "foo" and when it hits the "foo"
    inside the link above you will notice that the link containing the
    text becomes focused (it's a bit hard to explain, but you will see
    the link surrounded by a dotted line just as when you press to
    focus it in a normal browser). And the you can just press to
    activate it.

  2. Mhh, I'm thinking maybe it can be accomplished by adding some lines
    into the search logic? e.g., when a hit is found, check if the hit is
    inside a link, if yes, use javascript to focus that link e.g.
    $('...').focus()

On 23/10, Daniel Carl wrote:

I don't know this feature.

  1. Does vimperator use the normal search for that feature started by / or ?? If I search for 'foo' and there is a link with text 'foo' I use n or N to highlight this search match. If I hit <Enter> the link, containing the matching text is fired.
    This wouldn't be easy to implement in vimb, because search and hinting are totally different mechanisms.
  2. Or is this a type of hinting?

Reply to this email directly or view it on GitHub:
#131 (comment)

Lingnan Dai

@fanglingsu
Copy link
Owner

Ok, I know what you mean. I think this works because vimperator focus the searched element/text. Firefox and webkit do not focus the searches elements, so the <Enter> does not work. I'll check if we can simulate the behaviour with vimb too.

@fanglingsu
Copy link
Owner

I looked over the pentadactyl sources. Pentadactyl implements the search completely in JavaScript and can therefore focus the current found item.

Vimb uses the built in webkit search and highlighting mechanism that provides no API to focus the found item. Your suggestion to search by webkit and to set the focus via JavaScript does not work. We get no information where in the page the current found item is located, neighter from c code nor by a changed property in the DOM. At the time the only way to get this working is to implement searching via JavaScript.

I don't think that we can built this into vimb. But as a workaround, you can enable Caret-Browsing via :set caret! and then the focus should be on the found item.

@antoyo
Copy link

antoyo commented Aug 31, 2016

We can have this feature with the following mapping:

nmap <CR> :eval! window.getSelection().anchorNode.parentNode.click()<CR>

@fanglingsu
Copy link
Owner

@antoyo Thank you for this hint. I'll try to implement this in vimb so that the <CR> does only do the click when a search is currently active.

@fanglingsu fanglingsu reopened this Aug 31, 2016
@antoyo
Copy link

antoyo commented Aug 31, 2016

Cool.
If it is implemented in vimb, there is also a way to allow opening in a new tab with Ctrl+Enter (I don't think it is possible with only JavaScript).

fanglingsu added a commit that referenced this issue Aug 31, 2016
When a search is performed and the current highlighted result is part of a
link, a click event is triggered on the link to open it. Currently the click()
is done by JavaScript on the element so that we can't control if the target
open in current window or in a new one.
@fanglingsu
Copy link
Owner

I've pushed a first attempt to get this working. But vimb does not have control about the link target. tat means if the link or otherwise JavaScript crafted element want to open into new window a new window will be opened. I assume we have to reuse some of the hinting JavaScript to let vimb control where to open the element.

@fanglingsu
Copy link
Owner

This is already implemented.

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

No branches or pull requests

3 participants