gptel icon indicating copy to clipboard operation
gptel copied to clipboard

Make gptel-rewrite text replacement preserve evaporative overlays

Open daedsidog opened this issue 11 months ago • 3 comments

I am working on gptel integration into my extension.

gptel-rewrite is very nice and already does a lot of work such as adding the ability to diff/ediff changes. Though most of the functions are internal to gptel, I am planning, for now, to use gptel--rewrite-dispatch to create the overlays, until a better solution.

I've played around with it and it integrates very nicely, except for one issue: since I am using pre-existing overlays (not in any way related to the overlays gptel-rewrite creates), they are deleted because they have evaporate set to true when gptel-rewrite replaces the accepted text.

To circumvent this, I made the text replacement unobtrusive, by first inserting the new text, then deleting the old, instead of vice versa.

Besides the changes of convenience for my extension, it seems, to me, to also be desirable behavior, but I'll leave you to judge. My only concern is that it goes against some sort of standard convention that replacement always means total deletion and insertion.

daedsidog avatar Dec 20 '24 18:12 daedsidog

I've played around with it and it integrates very nicely, except for one issue: since I am using pre-existing overlays (not in any way related to the overlays gptel-rewrite creates), they are deleted because they have evaporate set to true when gptel-rewrite replaces the accepted text.

This is by design -- the rewrite "transaction" ends when you accept or reject the text. Otherwise there would be no way to actually get rid of the overlay.

Besides the changes of convenience for my extension, it seems, to me, to also be desirable behavior, but I'll leave you to judge. My only concern is that it goes against some sort of standard convention that replacement always means total deletion and insertion.

Could you explain why keeping the overlay around after accepting the response is desirable behavior? I've actually been considering deleting the overlay after running any operation, including diff/ediff.

karthink avatar Dec 22 '24 18:12 karthink

@karthink There is a misunderstanding, I am not talking about the gptel-rewrite overlay, which should rightly be removed.

I am talking about existing, unrelated overlays in the buffer, surrounding text. I want to replace the text of those overlays, and those overlays are evaporative.

Here's the behavior I wanted:

overlays

Previously, this would delete the existing overlay.

daedsidog avatar Dec 22 '24 18:12 daedsidog

Just a note to say that I haven't lost track of this, I'll get to it soon. I want to test it carefully as there are always unexpected edge cases with overlays.

karthink avatar Jan 13 '25 03:01 karthink