j0rd1smit / obsidian-copilot-auto-completion

MIT License
117 stars 12 forks source link

Option to Accept Partial Completions #7

Closed WilliamsJack closed 11 months ago

WilliamsJack commented 1 year ago

Hey Jordi! I love what you've done with this Copilot plugin.

I've added a configuration option to change the behaviour of the tab key from accepting the entire completion to accepting a single word. This would allow the user to more easily accept only the first parts of the completion, rather than having to backspace manually after the fact. I've done this by just transitioning back to the SuggestingState if any part of the suggestion remains.

The "Accept" quick action will still accept the whole suggestion, even when partial completions are enabled.

I think this will be helpful when the model generates long run-on paragraphs, but the user only wants to accept the first sentence or so. Rather than accepting everything and having to go back and delete what they don't want, they can just tab through until they're done.

Demo - https://youtu.be/WmYDkV52Ebc

Let me know if you have any specific guidelines for contributing, but I hope this is a good start. Thanks for creating this project!

j0rd1smit commented 1 year ago

Nice, this is awesome. Thanks for your contribution :) It's really nice that you include a demo video. Kudos. I think we can make it even nicer by not forcing the user to pick either the partial insertion or full insertion by having a dedicated hotkey for it. This also removes the need for an additional setting. So, what I was thinking was the following:

The big advantage here is that this opens the door to moving back and forth through the suggestion with the arrow keys. (Sadly, undoing insertion will require a bit more refactoring work, so let's keep that out of scope for now.)

Anyway, to bind the next word functionality to the right arrow key, we need to do the following:

  1. In src/render_plugin/completion_key_watcher.ts, we need to add right arrow key watcher something like:{key: "ArrowRight", run: handlePartialCompletionKey}.
  2. We should add a handlePartialAcceptCommand method to EventHandler and implement this in InitState, State, and EventListener.
  3. Move the partial accept logic to the handlePartialAcceptCommand method of SuggestingState.
  4. Provide the handlePartialAcceptCommand of EventListener to the src/render_plugin/completion_key_watcher.ts.

I was planning to do something like the above, but I did not have time yet. So, if you use the above approach in your PR, I'm more than happy to accept your PR.

WilliamsJack commented 1 year ago

Thanks! That's a good idea, much more useful to be able to choose one or the other at will. I'll be happy to implement that when I can!

j0rd1smit commented 1 year ago

Nice, good luck. Let me know if you get stuck or need additional input.

j0rd1smit commented 11 months ago

For me, it is ready to merge and release. @WilliamsJack for you as well? If not let me know or else I will merge by the end of the day

WilliamsJack commented 11 months ago

Sorry, GitHub is going to my junk folder for some reason! Yeah, this is ready. I have other ideas, but they're separate issues šŸ˜

WilliamsJack commented 11 months ago

Should there be a quick action for accepting the next word? I don't see much use in it personally, but it may be helpful for the workflow of other users.

j0rd1smit commented 11 months ago

Nah, I think it is fine without a quick action. if someone needs it, it is an easy addition.

j0rd1smit commented 11 months ago

I have other ideas, but they're separate issues šŸ˜

I happy to hear them