timhor / obsidian-editor-shortcuts

Obsidian plugin to add keyboard shortcuts commonly found in code editors such as Visual Studio Code (vscode) or Sublime Text
MIT License
356 stars 25 forks source link

Expand selection to word/phrase/etc? #38

Open dakrone opened 2 years ago

dakrone commented 2 years ago

I commonly use expanding selection in both Emacs and Intellij, for example, something like this (with the cursor and selection denoted by |):

testRegisteredDomainProcessor(buildEvent("goog|leapis.com"), "googleapis.com", null, "googleapis.com", null);
*expand*
testRegisteredDomainProcessor(buildEvent("|googleapis|.com"), "googleapis.com", null, "googleapis.com", null);
*expand*
testRegisteredDomainProcessor(buildEvent("|googleapis.com|"), "googleapis.com", null, "googleapis.com", null);
*expand*
testRegisteredDomainProcessor(buildEvent(|"googleapis.com"|), "googleapis.com", null, "googleapis.com", null);
*expand*
testRegisteredDomainProcessor(|buildEvent("googleapis.com")|, "googleapis.com", null, "googleapis.com", null);
*expand*
|testRegisteredDomainProcessor(buildEvent("googleapis.com"), "googleapis.com", null, "googleapis.com", null);|

It would be great if this worked for text also, for example, just expanding to the current word would be super helpful. Something like:

Hello. This "is so|me text. Yep."
Hello. This "is |some| text. Yep."
Hello. This "|is some text.| Yep."
Hello. This "|is some text. Yep.|"
Hello. This |"is some text. Yep."|
Hello. |This "is some text. Yep."|
|Hello. This "is some text. Yep."|

I picked the unit that made the most sense to me (word -> sentence -> quotes -> outside quotes -> enclosing sentence -> entire text), but even just having "expand to word" would be very useful.

Thanks for this plugin!

timhor commented 2 years ago

Most of these are already supported by this plugin, for instance:

For selecting sentences, you may find https://github.com/timhor/obsidian-sentence-navigator useful.

dakrone commented 2 years ago

They are supported, but not unified under a single keyboard shortcut, for example, I can bind ^W to Select word and hit it to go from foo b|ar baz to foo |bar| baz, but then hitting it a second time does nothing (instead of expanding again to |foo bar baz| like I expect). I'd have to bind three different keystrokes rather than continually hit the same key, as other code editors' implementations work.

Is there a way to get it to progressively widen as I hit a shortcut repeatedly?

timhor commented 2 years ago

Not at the moment, but I can look into how achievable that could be – follow along here: https://github.com/timhor/obsidian-editor-shortcuts/projects/1#card-83261606.

As a first step, I'd like to get quotes and brackets incrementally expanding, as discussed in #21. That should hopefully pave the way for other types of expansions.