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

feat: vim navigation with j/k keys within page #19

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

zigmars
Copy link

@zigmars zigmars commented Feb 25, 2021

Changed the behaviour of j/k keys to function as up down keys until the
end/start of the page is reached, then subsequent press of j/k should load the next/prev page as in original version.

As I have never used ruby / your particular build system, I didn't get to testing it.
Though I tested the functionality separately here: https://jsfiddle.net/vod98e1q/1/
If I'm not mistaken it should work for all major browsers: https://stackoverflow.com/questions/9439725/javascript-how-to-detect-if-browser-window-is-scrolled-to-bottom

Cheers,
Zigmars

Changed the behaviour of j/k keys to function as up down keys until the
end/start of the page is reached, in which case the next/prev page is
loaded as in original version.
@geeksam
Copy link
Owner

geeksam commented Feb 25, 2021

Looks nice at first glance. Thanks! I'll test it when I get a few minutes.

On the off chance you're incredibly bored and want to start playing with Ruby / testing this out, the process would be something like:

  • install a Ruby version manager (e.g., http://rvm.io/; https://asdf-vm.com probably also works)
  • use the above to install Ruby 2.6.3
  • gem install bundler
  • bundle install
  • bundle exec middleman server

... but those first two steps are non-trivial. :)

@geeksam
Copy link
Owner

geeksam commented Feb 25, 2021

Fun fact: I added the j/k nav code before I learned vim. I actually had to reverse my initial implementation because the coworker who'd suggested the keys in the first place pointed out that I'd got the directions backwards! :)

Works in Safari and Firefox. In trying it out on the actual content, though, I'm not sure about the usability of this change. If someone holds down 'j' for a second too long, they'll find themselves on another page, and when they go back, they'll be back at the top again. If they hold down 'k', they can jump back several pages at a time.

One potential solution might be to scroll to the bottom of the page when 'k' triggers a navigation change, but given that this is static HTML, passing that state on to the next page might be difficult to implement in an unobtrusive way.

Another alternative would be to use j/k to scroll and h/l to navigate to next/prev. Thoughts?

Again, thanks for taking the time to submit a PR!

* use j/k keys to navigate within page,
* use h/l keys to go to previous/next page.
@zigmars
Copy link
Author

zigmars commented Mar 7, 2021

Think like a git was useful to me and I am happy to contribute. :)
Also I am an anti-mouse type of a person. So partial navigation solution was a bit disappointing to me.
Nice backstory. :)

About the usability:
A friend, who is longtime vim user, suggested the same l/h for next/prev (without seeing your post), so I think that it might me a natural thing to do.

Cheers,
Zigmars

@geeksam
Copy link
Owner

geeksam commented Mar 7, 2021

Sounds good. I'll try to get to this in the next few days, unless you'd rather? Either way, thanks for the nudge. :)

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

Successfully merging this pull request may close these issues.

2 participants