KrazyManJ / obsidian-keyshots

🔮📝 Obsidian plugin that adds classic hotkey/shortcuts commands from popular IDEs like Visual Studio Code or JetBrains Family.
https://www.moritzjung.dev/obsidian-stats/plugins/keyshots/
MIT License
83 stars 2 forks source link

Feature request: Keyboard shortcuts to navigate foldables #5

Open webmasterraj opened 7 months ago

webmasterraj commented 7 months ago

I would like to share this feature request to add keyboard shortcuts that make it easier to navigate between foldables. Currently this is a pain, because the Obsdian editor by default does not properly handle folded content when using standard keyboard navigation.

I would like commands and hotkeys to quickly navigate between the different “foldable structures” in a file. When I say foldable structures, I really mean headers and lists (unsure if any other structures can be folded), with the down arrow, where clicking the down arrow results in the content being folded.

I propose that the following 3 VSCode commands to be implement in Obsidian:

  • “command”: “editor.gotoNextFold” – navigates the cursor to the next foldable structure in the current hierarchy
  • “command”: “editor.gotoPreviousFold” – navigates the cursor to the previous foldable structure in the current hierarchy
  • “command”: “editor.gotoParentFold” – navigates the cursor to the parent foldable from where the cursor is at

I would be happy to help with this implementation (I've helped with other plugins in the past). But I'm not too familiar with how this plugin works or how Obsidian manages the content tree and keyboard shortcuts, but maybe if someone provides guidance on how to do it, I can take a shot.

KrazyManJ commented 7 months ago

Thank you for your feature request (already marked and assigned to myself). I'll take a look to code this (it seems like a great challenge to achieve).

Also I am thankful for you offering help to participate in coding part, but my code uses custom made classes to manipulate with selections in much more easy approach than Obsidian API does. These classes are intuitive for me, but describing, documenting these classes for someone who never saw them would slow me down on so many levels, so I'll do it on my own.

One thing I would appreciate would be to think about shortcut for these commands (I know that in VSCode it has no default shortcut but I would like to have it in Keyshots Preset). If you would like to participate at least in this way, here are the rules for choosing shortcuts:

Again thank you, this will Improve this plugin on many levels. I'll comment here when I'll be done with these three commands. ❤️

KrazyManJ commented 6 months ago

Hey @webmasterraj , I've released new version of keyshots that adds desired commands. I've test them but take a look, and if would be everything okay, I'll close this issue as solved.

Link to this release is right here: https://github.com/KrazyManJ/obsidian-keyshots/releases/tag/2.2.0

webmasterraj commented 6 months ago

Thank you! What a quick turnaround :)

I did notice a couple things while playing with it that I thought I'd share. In a bullet list, I am able to use the shortcuts to navigate up and down the list items that have children (which is awesome). But for some reason it skips any items that don't have sub-items. I also realized there's no way to navigate up and down while staying at the same folding level.

In the example below, when I navigate using Go to next fold and Go to previous fold it will go first nested thing <=> next fold <=> subfold <=> children. I think this technically follows the "foldable" items, but it feels weird in practice because it jumps into subfold unexpectedly and it also skips the no children line.

image

What I was expecting from Go to previous fold and Go to next fold was first nested thing <=> next fold <=> no children <=> children. Now I realize that might not have been clear from my first post.

I also think a command to Go to child item could be useful while navigating too.

Of course, this might be more than you wanted to take on, and I really appreciate these additions as they are. Just wanted to share the feedback in case it's useful. Thank you!

webmasterraj commented 6 months ago

Oh, these are the keyboard shortcuts I am using fyi.

image
KrazyManJ commented 4 months ago

So is everything okay or something that you want to change, enhance?

Anthonyae commented 4 months ago

I would also add that I am seeing the same thing @webmasterraj mentioned, regarding the folds going to a sub-level when using the go to previous and next fold commands. It seems to skip hierarchy levels sometimes. And there is also the issue where the cursor sometimes goes into a level lower in the fold hierarchy and then back up. I have an image to explain both here. I marked a line next to each bullet that the commands take you. And added the text itself so you can test it on your editor.

Issue: next and previous don't traverse the full list of folds for its current hierarchy.

image
- Parent fold
    - Fold A
        - Sub fold A1
    - Fold B
        - Sub fold B1
        - Sub fold B2
        - Sub fold B3
    - Fold C

issue: next and previous ignore parts of the traversal that don't have children items.

image
- Parent fold
    - Fold A
        - Sub fold A1
    - Fold B
        - Sub fold B1
            - Sub fold B1-1
    - Fold C
        - Sub fold C1
    - Fold D
    - Fold E

Its not the end of the world. But it does make the behavior weird sometimes and feel off. But again thank you @KrazyManJ for the work on adding them, even as they are now!

EDIT: One more thing to add here. I read through the original request. And it looks like the current implementation does match what was requested there. The shortcuts do navigate through all foldable structures in the file. Which would be headers and list items with child bullets. It seems that headers are implicitly foldable on their own. But bullet points are not foldable implictily, they have to have child bullet points within them to be considered foldable. Therefore the commnds to navigate next and previous folds work as they should within the definition.

What I thought the command did was treat bullets as implicitly foldable as well. So more so as a command to go to the next and previous bullet in a given level of a hierarchy like the folds (A, B, C, D, E) that I have listed above, if I started using the command at that level. Or navigate the sub folds only if I started the command with my cursor there.

KrazyManJ commented 2 months ago

Hello @webmasterraj and @Anthonyae , thank you for your responses.

Now I've fixed behavior of these commands. I will release new version this day, so stay focused.

As you mentioned @Anthonyae , your expected behavior is great but it has one mistake. Any kind of list member, that does not have a child, is not considered as foldable, so I am not going to implement to target these members, because it will break rule of what should this command do: Navigate to next foldable. Anyways other expectations now will be satisfied with new version (as I hope so).

Thank you for your responses, and having commitment to enhance Keyshots! ♥️

I'll leave issue open until everything will be okay!

KrazyManJ commented 2 months ago

Few days ago I've released Keyshots new version here:

https://github.com/KrazyManJ/obsidian-keyshots/releases/tag/2.3.0