flippidippi / sVim

Safari extension with shortcuts similar to Vim
Other
734 stars 51 forks source link

Can you add / search for text and jump to links like Vimium does #84

Open nikitavoloboev opened 6 years ago

nikitavoloboev commented 6 years ago

It would be really amazing if you could press / key and a vim like search prompt opens. Jumping to a text that is a hyperlink will then let you press return on it to go to the link.

Vimium does it this way and its really useful. Is this possible to do in sVim? I am willing to try and add this feature if it is possible. Thank you.

luchenyuxx commented 6 years ago

It's absolutely possible in sVim. Feel free to implement it. I will also try it on my side.

nikitavoloboev commented 6 years ago

Hey @luchenyuxx

Just wanted to ask if there was any update on this feature. 🙂

I looked at sVim code and don't even know where to start adding support for this. 😞

luchenyuxx commented 6 years ago

Hello @nikitavoloboev, I was working on another feature recently (you can check my pull request). To start, you can check the file sVimTab.js, this file is loaded when a page is loaded. There is a command list there. Add your new command there. Another file is sVimGlobal.js. The default key binding is defined there. Use safari extension builder to load the project into safari.

nikitavoloboev commented 6 years ago

Hey @luchenyuxx

Did you by chance have any time to look at this?

I can understand how I can map / to do the searching but. But I also want it to allow users to go to link all from keyboard by pressing enter if the selected text is a link just like Vimium does.

nikitavoloboev commented 6 years ago

Hey @luchenyuxx. Can you guide me on how I can make this change. This is literally the only thing I wish existed in sVim that it currently doesn't do. 😞

Thank you.

luchenyuxx commented 6 years ago

@nikitavoloboev Sorry for the late response. Sure, I can try to write a Contributing.md. Generally speaking, the codes loaded once are in sVimGlobal.html, and for every tab opened, the codes in sVimTab.js are executed. You can start from this. You can use Safari extension builder to build and load this project.

pysnow530 commented 6 years ago

A great feature!👍

rtgoodwin commented 6 years ago

@nikitavoloboev did you end up with working code for / searching? I was deep diving into safari but can't seem to find a way to trigger it. I'd settle for it just triggering the native Find in page, but if you did something a bit better like Vimium I'd love to know. :)

Thanks!

flyingotter17 commented 6 years ago

I just switched back to safari, from Firefox, which I switched to from Chrome, where I first started using Vimium and I must say that /search is the most essential part of Vimium. I am going to try to implement this myself though I have no real clue where to start, but the trial and error is half the fun. :) If anyone has successfully implemented this, it would deeply appreciated if you could post the code here for reference!

odnoletkov commented 5 years ago

BTW in Vimium there is even more advanced feature for this – filtered hints. Instead of using full-text search to target links (which is sometimes inconvinient because it would hit non-links text as well) it changes the way link navigation mode (f key) operates. Instead of adding arbitrary labels to links it uses link's text itself to filter and navigate to target link.

Firefox has a similar feature built-in – called 'Quick Find Link' (' key)

Now that is a feature I would absolutely love to have in sVim as well. I find it the best option for mouseless links navigation.

shaunlebron commented 4 years ago

For those who care, I found a minimal way to do this without sVim:

  1. Use Cmd+F to find and highlight the link (Enter to cycle).
  2. Press Esc to exit the search box.
  3. Press Esc again to “focus” the link (requires the setup below).
  4. Use the native Enter or Cmd+Enter to open it.

To make Step 3 work, I use the PageExtender.app safari extension so that ~/.js/default.js is loaded in every page with the following code:

// Press Escape to focus a highlighted link
window.addEventListener('keypress', e => {
  if (e.key == "Escape") {
    const sel = window.getSelection()
    const node = sel?.anchorNode?.parentNode
    if (node?.tagName.toLowerCase() == 'a') {
      e.preventDefault()
      sel.removeAllRanges()
      node.focus()
    }
  }
})