Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why isn't a prompt buffer used? #379

Closed
tmillr opened this issue Jul 28, 2024 · 4 comments · Fixed by #400
Closed

Why isn't a prompt buffer used? #379

tmillr opened this issue Jul 28, 2024 · 4 comments · Fixed by #400
Labels
enhancement New feature or request question Further information is requested

Comments

@tmillr
Copy link

tmillr commented Jul 28, 2024

One thing I find annoying is that after I scroll up to view the history, entering insert mode then allows me to edit the current line (e.g. history) instead of taking me back to the prompting line/area. It'd be nice if entering insert mode took me back to the current prompt automatically (and IIRC, this is precisely how prompt buffers work in neovim).

Here's my temporary workaround, although there may be a better way to implement this internally (using a prompt buffer (see :help prompt-buffer), or, extmarks, etc.):

vim.api.nvim_create_autocmd('FileType', {
  group = augroup,
  -- pattern = 'copilot-*',
  pattern = 'copilot-chat',
  callback = function(info)
    vim.api.nvim_create_autocmd('InsertEnter', {
      group = augroup,
      buffer = info.buf,
      desc = 'Move to last line',
      -- nested = true,
      callback = function()
        vim.cmd 'normal! 0'

        if vim.fn.search([[\m^##\s\+\S]], 'cnW') > 0 then
          vim.cmd 'normal! G$'
          vim.v.char = 'x'
        end
      end,
    })
  end,
})
@deathbeam
Copy link
Collaborator

This is first time I hear something like prompt-buffer exists :d Sounds like good idea tho because this is precisely what we want to achieve anyway with otu current implementation.

@deathbeam deathbeam added the enhancement New feature or request label Jul 28, 2024
@xlucn
Copy link

xlucn commented Aug 25, 2024

I tried to directly set buftype=prompt, and that works in a degree. But, there are some issues.

  1. I can use Enter to write a multiple-line question, but I can't edit all previous lines except the current one.

  2. When I quit neovim, it prevents me with the error

E37: No write since last change
E162: No write since last change for buffer "copilot-chat"

The default buftype for ft=copilot-chat is nofile, which will allow quitting neovim without taking care of it. Anyone knows a more proper practice of using buftype=prompt?

@deathbeam
Copy link
Collaborator

deathbeam commented Aug 26, 2024

So I experimented with prompt buffer a bit and my thoughts are:

It simplifies a lot of the prompt handling code but being able to only edit 1 line is basically no-go. It makes asking complex questions basically impossible. I was able to solve the quitting issue rather easily tho so thats solvable for sure.

I would be for closing this issue as I think the prompt buffer behaviour even though its kinda nice the 1 line thingy is just so bad.

EDIT:

But when entering insert mode, going to last line is probably fine I guess? As that behaviour is rly nice for sure. But its also probably replicable without prompt buffer

@deathbeam deathbeam added the question Further information is requested label Aug 26, 2024
deathbeam added a commit to deathbeam/CopilotChat.nvim that referenced this issue Aug 29, 2024
- Cleanup auto insert behaviour and move it to chat.lua
- Add support for moving cursor to end of buffer before entering insert mode in the chat buffer
- Cleanup configuration (move yank register config near the mapping)

Closes CopilotC-Nvim#379

Signed-off-by: Tomas Slusny <[email protected]>
deathbeam added a commit to deathbeam/CopilotChat.nvim that referenced this issue Aug 29, 2024
- Cleanup auto insert behaviour and move it to chat.lua
- Add support for moving cursor to end of buffer before entering insert mode in the chat buffer
- Cleanup configuration (move yank register config near the mapping)

Closes CopilotC-Nvim#379

Signed-off-by: Tomas Slusny <[email protected]>
@tmillr
Copy link
Author

tmillr commented Aug 29, 2024

But when entering insert mode, going to last line is probably fine I guess? As that behaviour is rly nice for sure. But its also probably replicable without prompt buffer

Yeah it can be replicated. IMO there's no reason to be editing/inserting anywhere but within the current (i.e. bottommost) prompt. So I'd make it so that it takes you there automatically if you are above that section and enter insert mode. You probably don't want to do it if you are already in current prompt section however, as you may be trying to edit earlier lines (not the last one) within the current prompt.

But yeah, I think the last column of the last line is the most logical place to put it in this case (you could also get fancy and do other stuff too, but that's the gist).

deathbeam added a commit to deathbeam/CopilotChat.nvim that referenced this issue Aug 30, 2024
- Cleanup auto insert behaviour and move it to chat.lua
- Add support for moving cursor to end of buffer before entering insert mode in the chat buffer
- Cleanup configuration (move yank register config near the mapping)

Closes CopilotC-Nvim#379

Signed-off-by: Tomas Slusny <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants