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

Many vim-like shortcuts for navigating and manipulating blocks #63

Closed

Conversation

tntmarket
Copy link
Contributor

@tntmarket tntmarket commented May 18, 2020

This introduces a variety of vim like keyboard shortcuts for navigating blocks/pages, opening links, editing and selecting blocks.

It mainly revolves around remembering a "Currently selected block", which is analogous to the cursor in vim.

Demo: https://www.youtube.com/watch?v=ZxtT05CjOyo

I believe this addresses #47, #54, and #18, although in a somewhat intrusive way

Work In Progress

Still need to:

  • pull master, resolve conflicts
  • organize the commits (they're kind-of a mess)
  • organize the code (could share more code existing modules)
  • write documentation/instructions where applicable
  • add tests where applicable
  • figure out how to turn off the feature by default (it's kind-of intrusive)
  • revert the temporary commit

@Stvad
Copy link
Member

Stvad commented May 18, 2020

wow, this looks amazing! will look at it closer tonight-ish

@Stvad
Copy link
Member

Stvad commented May 18, 2020

some want's from just trying it out for a bit

  • u in normal mode should do "undo"
  • character hints >> number hints (though this has problem with conflicting with things/etc, so it's not that straightforward)
  • enter should probably map to "go to insert mode" too
  • would be nice if l were to toggle between the page and sidebar (vs having 2 separate shortcuts)
  • shift-o to create block above
  • in queries/mentions - Want hints to be able to expand various levels of "breadcrumbs" (and probably for going to the actual page as-well)
  • hints for complex pages are a bit confusing (not sure how to make them better)
  • would be awesome if moving blocks were to work in normal mode (though if I understand it correctly it's more of a Roam thing?)

More general Roam toolkit related:

  • make delete block work in "normal mode" and map it to dd
  • vim normal mode SRS shortcuts 😍
  • normal mode shortcut to copy block reference/block embed (y/Y)

Surfingkeys:

  • still want hints from Surfingkeys at times - would be nice to create a config for it that disables overlapping commands, but keeps nav hints working/etc

@tntmarket
Copy link
Contributor Author

tntmarket commented May 18, 2020

Added a commit for undo/redo, and shift+o to prepend a line

The hints can be remapped from numbers to keys, maybe we can set the default hint keys to something else closer to home row. Maybe there should option to toggle the hints on/off, or have hints be nested in their own mode.

I was considering extending h/l to navigate to the left sidebar as well. I personally like it when spatial shortcuts "dead end" at the edge of the window, cause I don't have to worry about "overshooting". But I think a "toggle panel" or "cycle through panels" would be good too.

@Stvad
Copy link
Member

Stvad commented May 18, 2020

Hmm, undo/redo/shift-o don't seem to work for me for some reason 🤔

@tntmarket
Copy link
Contributor Author

So one strange thing I noticed is that whenever I introduce a new key binding, I have to

  1. go to the settings popup
  2. click into the newly introduce text input for the new shortcut
  3. wait for the green checkmark to appear

In order for the shortcut to start working (this is while I'm doing yarn run watch)

@Stvad
Copy link
Member

Stvad commented May 19, 2020

So one strange thing I noticed is that whenever I introduce a new key binding, I have to

1. go to the settings popup

2. click into the newly introduce text input for the new shortcut

3. wait for the green checkmark to appear

In order for the shortcut to start working (this is while I'm doing yarn run watch)

ouch, that seems like a bug in settings, can you create an issue for that?

@Stvad
Copy link
Member

Stvad commented May 19, 2020

also as a general remark - this PR is kind of large. if you can think of meaningful way to split it up in several ones to make review easier - would be appreciated. If not it's ok, but it's going to take me a bit to go through it

@Stvad
Copy link
Member

Stvad commented May 19, 2020

One weird thing: In the morning I remapped "Select Panel Left" to Shift+L and it worked at that time, but it doesn't anymore after some of the updates

@Stvad
Copy link
Member

Stvad commented May 19, 2020

btw just fui - key sequences should also work - https://github.com/greena13/react-hotkeys#key-combinations-vs-sequences (you just have to specify them with the space within them)
so we can stay closer to VIM in a variety of mappings

},
})

export const imap = (settings: BlockNavigationModeSetting): Shortcut =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like it should be straightforward to write a function to generate all the functions below based on a given predicate/list of modes

@tntmarket
Copy link
Contributor Author

also as a general remark - this PR is kind of large. if you can think of meaningful way to split it up in several ones to make review easier - would be appreciated. If not it's ok, but it's going to take me a bit to go through it

For sure, apologies for that. I'll go through the commits and reorganize them :p

@tntmarket
Copy link
Contributor Author

So one strange thing I noticed is that whenever I introduce a new key binding, I have to

1. go to the settings popup

2. click into the newly introduce text input for the new shortcut

3. wait for the green checkmark to appear

In order for the shortcut to start working (this is while I'm doing yarn run watch)

ouch, that seems like a bug in settings, can you create an issue for that?

Created #64

@tntmarket tntmarket marked this pull request as draft May 19, 2020 03:06
import {Selectors} from '../../roam/roam-selectors'
import {delay} from '../../utils/async'

export type Mode = 'INSERT' | 'VISUAL' | 'NORMAL'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should these be Enums? (it's not an assertion but a question :) )

@Stvad
Copy link
Member

Stvad commented May 19, 2020

toggle fold does not work in references, unless you hover the mouse on top of the block

@Stvad
Copy link
Member

Stvad commented May 19, 2020

Btw, I often have blocks with more then 4 things that can be referenced, what's up with the limit to 4?:)

@Stvad
Copy link
Member

Stvad commented May 19, 2020

If I click on the todo checkbox - hints within the block disappear. and I need to move focus elsewhere and back before they appear. I suppose it's pertinent to the discussion on whether they should be show all the time or on-demand

@tntmarket
Copy link
Contributor Author

Btw, I often have blocks with more then 4 things that can be referenced, what's up with the limit to 4?:)

Oh yeah, 4 is too low, I'm thinking something like 10 might be a reasonable upper bound. But then again, the whole hint UX deserves some more consideration

@tntmarket
Copy link
Contributor Author

FYI, heads up that visual mode and insert mode are unreliable for me, sometimes the selection gets stuck, and keys stop working. I'll look more into this.

In the React Hotkey debug logs, I sometimes get into a state where pressing "J" is interpreted as "J+whateverWasLastPressed", even if I'm only pressing "J". Unfocusing/focusing the window usually fixes the problem.

I think this has to do with some race condition related to focusing/unfocusing blocks.

@Stvad
Copy link
Member

Stvad commented May 19, 2020

btw added unmapAllExcept(['f', '/', 'C', '?'], /roamresearch\.com/i); to Surfingkeys config to get just the hints (will probably add more whitelisting later)

@Stvad
Copy link
Member

Stvad commented May 19, 2020

Tab/shift-tab should work in normal mode (probably generally true for anything that you'd expect to work with "native" selection)

@Stvad
Copy link
Member

Stvad commented May 19, 2020

Also there should probably be mapping for "jump to last block that is not in linked references"

@houshuang
Copy link

Just to say that this is absolutely mindblowing... I've been dreaming of something like this! I hate how all the blocks change when you move up/down with a keyboard (especially images etc). I probably even use fewer Markdown links because of that...

This will quickly become something I could not live without.

Would be very useful with an overview of keyboard shortcuts :) I looked at the source code and tried stuff - worked very well! Love how smooth it feels...

Would love line numbers (even more fancy is relative line numbers) on the left, and being able to do 10k etc to jump up to a specific line.

Also hope I can remap Esc to jk keychord as I have in my Vim setup :)

Fantastic work! 🎉🔥

@classicrob
Copy link

classicrob commented May 20, 2020

This is absolutely amazing, incredible work. I'm sure as I'll play around with this I'll have more feedback, but for now the only major thing that is missing for me is unwinding context on a block in a query or a linked reference, or while zoomed in on a block.

@Stvad Stvad added the enhancement New feature or request label May 20, 2020
@tntmarket
Copy link
Contributor Author

tntmarket commented Jun 25, 2020

Also added tntmarket#5, in case anyone wants to try a horizontal sidebar css theme, and wants h/l to work

@Stvad
Copy link
Member

Stvad commented Jun 26, 2020

@tntmarket regarding yarn.lock I removed it mainly because I use npm and GitHub was screaming at me because there were old things in yarn.lock. It's probably ok to add it back.
any good method to keep npm and yarn lock files in sync automagically?

@the-nurk
Copy link

I can't contribute, but please don't let this die. vim+roam would be heaven

@Stvad
Copy link
Member

Stvad commented Jun 26, 2020

@nicksettoon I don't think this is in any danger of dying :) @tntmarket and myself are working on bringing this to master. I use it and love it. Absolutely looking forward to pushing it out to the other users!

@the-nurk
Copy link

the-nurk commented Jun 26, 2020

@nicksettoon I don't think this is in any danger of dying :) @tntmarket and myself are working on bringing this to master. I use it and love it. Absolutely looking forward to pushing it out to the other users!

My Hero

@tntmarket
Copy link
Contributor Author

@tntmarket regarding yarn.lock I removed it mainly because I use npm and GitHub was screaming at me because there were old things in yarn.lock. It's probably ok to add it back.
any good method to keep npm and yarn lock files in sync automagically?

Oh actually nvm, I'll use npm. For some reason I thought npm used yarn.lock as it's lockfile lol

@Stvad
Copy link
Member

Stvad commented Jun 27, 2020

btw - I'm curious on why make the PRs internal and not to the master here?

@tntmarket
Copy link
Contributor Author

Oh, I thought it'd make the diffs look more clean, so the later ones wouldn't include changes from the earlier ones

…-hotkeys and provide a more convenient interface that does what you'd expect
- Basic navigation, insert, and visual mode commands
- Abstractions on top of Roam that make it more convenient to implement Vim Mode. I didn't integrate this with core/roam yet, since I wanted to get feedback on whether they were the right abstractions first
@Stvad
Copy link
Member

Stvad commented Jun 30, 2020

outside of scope of this, but just fyi created #95

@tntmarket
Copy link
Contributor Author

Since we're getting close to releasing this, I created #104 to update the documentation

@tntmarket
Copy link
Contributor Author

Gonna close this, as the functionality has been merged via other PRs and now. Looking forward to the app store release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request navigation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants