fix some issues in dict key completion

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

The leading text was being omitted, causing loss of text when greedy=True

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