This should definitely be a new answer.
An editor should improve an post grammatically, visually, and based on their comprehension of the problem (and many times the comments of the OP), but should also strive to preserve the original intention of the OP.
In this case, the edit clearly deviates from the original answer, adding much more content and even changing the commands that were present in the original answer. The rejection reasons in the Suggested Edits review queue include the following:
Either one of these reasons is fine for the edit to be rejected against.
Another reason for rejecting it is that the answer was judged based on its original content and obtained 4 upvotes. Completely changing it, as in this case, would require for the answer to be judged again by the people who voted. Obviously, this is not feasible, as the voters may never see this post again.
All in all, this is a bad edit but probably a good answer and the editor should get the merit of it.