Fix search & replace bug.

Happened if the string you're replacing with contains the one that is being
replaced. There was a silly misuse of local variable and miscalculation of the
cursor position as a result.
When doing local buffer autocompletion, clone byte slice in some cases.

Otherwise it causes a bug when the autocompletion proposal comes from the same
line we're currently editing.