Automattic / Automattic/harper
Obsidian plugin hotkey to show suggestions for the word under the cursor
- Dominant language
- Rust
- Stars
- 15.4k
- Forks
- 627
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 106
Description
**What problem does this solve?**
At the moment, the Obsidian plugin is not very keyboard friendly, and in some places very unintuitive, in my opinion.
Using the default Obsidian spellchecker, I can place the text cursor over a misspelled word, hit the `Menu` key (or bind `Show context menu under cursor` to a hotkey. I use `Ctrl+.`) to open the context menu, then use the arrow keys and `Enter` to move down the list and select a suggestion or add to dictionary.
To do something similar with the Obsidian Harper plugin, I first have to create 5 hotkeys (6 if I want to close the popup without taking action, or 8 if I also want to ignore diagnostics or disable rules): Jump to next suggestion, add to dictionary, and apply suggestion 1/2/3.
It would be nice if the popup could be navigated with `Tab`/`Shift+Tab` and `Enter`, or the arrow keys. Unfortunately the popup is not focused unless explicitly clicked on using the mouse, so attempting to use `Tab` just indents the current line instead. Arrow keys are not supported, even when focused.
There's also a few other problems with using the Jump to next suggestion hotkey to open the popup.
First, if the cursor is at the start, or anywhere inside an underlined word, the next suggestion is actually the underlined word *after* the one the cursor was on. This means you have to place the text cursor at least one character *before* the word you want to fix, not inside, or even at the start of it.
Second, the editor does not scroll to the next suggestion if it's not currently visible. The popup does open, but it's not visible to the user.
**Proposed Solution**
I propose a new hotkey that opens the suggestion popup for the word that is currently under the text cursor and then importantly, focuses the popup so it can be navigated using `Tab`, `Shift+Tab`, and `Enter`.
The "Ignore Diagnostic" and "Disable Rule" elements should also be changed so they get a tab index. They're currently just `div` elements which means they can't be navigated to using the keyboard. A better element would be a `button` like the suggestions and add to dictionary buttons.
Support for the arrow keys instead of the standard `Tab` navigation would also be nice, but that would require a custom implementation.
**Component**
- [ ] Core engine
- [x] Plugin/Extension
- [ ] Other: _____
**Additional Context**
Some of the problems could probably be bug reports on their own, like the popup not focusing when activated with the keyboard, the editor not scrolling the popup into view, and some elements not being navigate able, but I decided to just put it all in here since they're part of a bigger problem. A better issue title might've even been "Improve the keyboard experience of the Obsidian plugin".
I can create individual issues for the smaller problems if you feel that's necessary.
Contributor guide
Research direction
Start by locating the Obsidian plugin's hotkey handling and suggestion popup implementation, then inspect how the popup is focused and how its controls are represented. Reproduce the cursor-position and off-screen cases described in the issue. Done means a hotkey opens the current word's popup with keyboard focus, keyboard navigation works for all listed actions, and the popup is visible.
Written by the indexing model from the issue text.
Assessment
- Domain
- accessibility, frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100