didn't look in details yet, but I don't see the need for an intermediate buffer. you just need to edit_line_delete( console, ctx->cursor, ctx->len ); to clear edit line after cursor, then insert history line + ctx->cursor, length 1 or til end of line.
also quick testing on windows rather suggests that's the current_history line that should be used instead of last line in history
I didn't check if history is modified by these operations