ChatGPT.nvim
ChatGPT.nvim copied to clipboard
Improved newline handling in interactive code edits and edit actions
The following is from my personal fork to improve editing (interactively or via actions) of visual selections; maybe it's interesting for main? In any case, thanks for the great plugin :).
Currently, if a visual selection is edited (either interactively or via an edit action), an unwanted newline was inserted. This pull request avoids such newlines.
The changes (a) ensure that the visual selection is yanked/pasted without creating additional newlines and (b) enforce that ChatGPT's answer ends in exactly as many newlines as the visual selection. The latter is necessary since ChatGPT seems to always add a newline at the end of its answer, even if the input did not contain one. Note that this might be considered a downside of the pull request, since requests like add 3 newlines at the end
are now ignored.
Notable changes:
- Moved the handling of a non-existing current/previous visual selection into
Utils.get_visual_lines
. - Got rid of
Utils.get_lines
,Utils.get_visual_start_end
, sinceUtils.get_visual_lines
seems now simple enough to handle this directly. -
Utils.end_col
is no longer needed andUtils.paste
are also gone (replaced by a direct call tovim.api.nvim_buf_set_text
). -
Utils.split_string_by_line
: Previously bothsome text
andsome text\n
resulted in{"some text", ""}
(i.e., two lines). Now only the latter does, while the former yields{"some text"}
.
Good job! Could you please fix formatting to pass the pipeline
Ah sorry, didn't see the formatting checks. Done.