fix some issues in dict key completion

The main change: don't auto-close contexts (str, bracket) if they are not opened within the text to match

The leading text was being omitted, causing loss of text when greedy=True. This could also affect greedy=False in some cases.

In practice, this means that strings and brackets will not be closed on dict keys when greedy=False.