I thought I'd ask for feedback from the group before posting this as a bug. It feels like one to me, but others may like it...
In the example code below, if you place the caret within the word Hello and then do CTRL-W (Select Word at Caret) at least 3 times and then do a Surround With Live Template, IDEA considers the context to be Java String.
However, if you start by placing the caret within, say, the word println and then do CTRL-W at least 4 times (which yields the same selection as doing CTRL-W 3 times in the above case) and then do a Surround With Live Template, IDEA considers the context to be Java Code.
public class SurroundWithLiveTemplateTest
public void foo()
I expected the context to be determined from what I have selected, not simply where the caret is located.
The above example is perhaps clearer because the context is Java Code at both the ends of the selection. I guess the problem arises when there's a mix of contexts, e.g. a selection that includes a line of code followed by a comment. In the case of more than one context, maybe IDEA could instead present all applicable Live Templates?