timhor/obsidian-editor-shortcuts

Expand selection to word/phrase/etc?

Opened this issue · 3 comments

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!

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

  • Word: Select word (from a cursor, it will expand to the current word)
  • Quotes/brackets: Expand selection to quotes or brackets
  • Entire line: Select line

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

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?

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.