feat(api): add switch sidebar focus (#709)
This commit is contained in:
parent
964715be64
commit
86ba5a468b
87
README.md
87
README.md
@ -159,13 +159,11 @@ require('avante').setup ({
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
|
||||||
> [!IMPORTANT]
|
> [!IMPORTANT]
|
||||||
>
|
>
|
||||||
> For `avante.tokenizers` and templates to work, make sure to call `require('avante_lib').load()` somewhere when entering the editor.
|
> For `avante.tokenizers` and templates to work, make sure to call `require('avante_lib').load()` somewhere when entering the editor.
|
||||||
> We will leave the users to decide where it fits to do this, as this varies among configurations. (But we do recommend running this after where you set your colorscheme)
|
> We will leave the users to decide where it fits to do this, as this varies among configurations. (But we do recommend running this after where you set your colorscheme)
|
||||||
|
|
||||||
|
|
||||||
> [!IMPORTANT]
|
> [!IMPORTANT]
|
||||||
>
|
>
|
||||||
> `avante.nvim` is currently only compatible with Neovim 0.10.1 or later. Please ensure that your Neovim version meets these requirements before proceeding.
|
> `avante.nvim` is currently only compatible with Neovim 0.10.1 or later. Please ensure that your Neovim version meets these requirements before proceeding.
|
||||||
@ -341,21 +339,22 @@ Given its early stage, `avante.nvim` currently supports the following basic func
|
|||||||
|
|
||||||
The following key bindings are available for use with `avante.nvim`:
|
The following key bindings are available for use with `avante.nvim`:
|
||||||
|
|
||||||
| Key Binding | Description |
|
| Key Binding | Description |
|
||||||
|-------------|-------------|
|
| ----------------------------------------- | -------------------------------------------- |
|
||||||
| <kbd>Leader</kbd><kbd>a</kbd><kbd>a</kbd> | show sidebar |
|
| <kbd>Leader</kbd><kbd>a</kbd><kbd>a</kbd> | show sidebar |
|
||||||
| <kbd>Leader</kbd><kbd>a</kbd><kbd>r</kbd> | refresh sidebar |
|
| <kbd>Leader</kbd><kbd>a</kbd><kbd>r</kbd> | refresh sidebar |
|
||||||
| <kbd>Leader</kbd><kbd>a</kbd><kbd>e</kbd> | edit selected blocks |
|
| <kbd>Leader</kbd><kbd>a</kbd><kbd>f</kbd> | switch sidebar focus |
|
||||||
| <kbd>c</kbd><kbd>o</kbd> | choose ours |
|
| <kbd>Leader</kbd><kbd>a</kbd><kbd>e</kbd> | edit selected blocks |
|
||||||
| <kbd>c</kbd><kbd>t</kbd> | choose theirs |
|
| <kbd>c</kbd><kbd>o</kbd> | choose ours |
|
||||||
| <kbd>c</kbd><kbd>a</kbd> | choose all theirs |
|
| <kbd>c</kbd><kbd>t</kbd> | choose theirs |
|
||||||
| <kbd>c</kbd><kbd>0</kbd> | choose none |
|
| <kbd>c</kbd><kbd>a</kbd> | choose all theirs |
|
||||||
| <kbd>c</kbd><kbd>b</kbd> | choose both |
|
| <kbd>c</kbd><kbd>0</kbd> | choose none |
|
||||||
| <kbd>c</kbd><kbd>c</kbd> | choose cursor |
|
| <kbd>c</kbd><kbd>b</kbd> | choose both |
|
||||||
| <kbd>]</kbd><kbd>x</kbd> | move to previous conflict |
|
| <kbd>c</kbd><kbd>c</kbd> | choose cursor |
|
||||||
| <kbd>[</kbd><kbd>x</kbd> | move to next conflict |
|
| <kbd>]</kbd><kbd>x</kbd> | move to previous conflict |
|
||||||
| <kbd>[</kbd><kbd>[</kbd> | jump to previous codeblocks (results window) |
|
| <kbd>[</kbd><kbd>x</kbd> | move to next conflict |
|
||||||
| <kbd>]</kbd><kbd>]</kbd> | jump to next codeblocks (results windows) |
|
| <kbd>[</kbd><kbd>[</kbd> | jump to previous codeblocks (results window) |
|
||||||
|
| <kbd>]</kbd><kbd>]</kbd> | jump to next codeblocks (results windows) |
|
||||||
|
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
>
|
>
|
||||||
@ -364,21 +363,20 @@ The following key bindings are available for use with `avante.nvim`:
|
|||||||
|
|
||||||
## Highlight Groups
|
## Highlight Groups
|
||||||
|
|
||||||
|
| Highlight Group | Description | Notes |
|
||||||
| Highlight Group | Description | Notes |
|
| --------------------------- | --------------------------------------------- | -------------------------------------------- |
|
||||||
|-----------------|-------------|-------|
|
| AvanteTitle | Title | |
|
||||||
| AvanteTitle | Title | |
|
| AvanteReversedTitle | Used for rounded border | |
|
||||||
| AvanteReversedTitle | Used for rounded border | |
|
| AvanteSubtitle | Selected code title | |
|
||||||
| AvanteSubtitle | Selected code title | |
|
| AvanteReversedSubtitle | Used for rounded border | |
|
||||||
| AvanteReversedSubtitle | Used for rounded border | |
|
| AvanteThirdTitle | Prompt title | |
|
||||||
| AvanteThirdTitle | Prompt title | |
|
| AvanteReversedThirdTitle | Used for rounded border | |
|
||||||
| AvanteReversedThirdTitle | Used for rounded border | |
|
| AvanteConflictCurrent | Current conflict highlight | Default to `Config.highlights.diff.current` |
|
||||||
| AvanteConflictCurrent | Current conflict highlight | Default to `Config.highlights.diff.current` |
|
| AvanteConflictIncoming | Incoming conflict highlight | Default to `Config.highlights.diff.incoming` |
|
||||||
| AvanteConflictIncoming | Incoming conflict highlight | Default to `Config.highlights.diff.incoming` |
|
| AvanteConflictCurrentLabel | Current conflict label highlight | Default to shade of `AvanteConflictCurrent` |
|
||||||
| AvanteConflictCurrentLabel | Current conflict label highlight | Default to shade of `AvanteConflictCurrent` |
|
| AvanteConflictIncomingLabel | Incoming conflict label highlight | Default to shade of `AvanteConflictIncoming` |
|
||||||
| AvanteConflictIncomingLabel | Incoming conflict label highlight | Default to shade of `AvanteConflictIncoming` |
|
| AvantePopupHint | Usage hints in popup menus | |
|
||||||
| AvantePopupHint | Usage hints in popup menus | |
|
| AvanteInlineHint | The end-of-line hint displayed in visual mode | |
|
||||||
| AvanteInlineHint | The end-of-line hint displayed in visual mode | |
|
|
||||||
|
|
||||||
See [highlights.lua](./lua/avante/highlights.lua) for more information
|
See [highlights.lua](./lua/avante/highlights.lua) for more information
|
||||||
|
|
||||||
@ -405,6 +403,7 @@ If one wish to custom prompts for each mode, `avante.nvim` will check for projec
|
|||||||
the following patterns: `*.{mode}.avanterules`.
|
the following patterns: `*.{mode}.avanterules`.
|
||||||
|
|
||||||
The rules for root hierarchy:
|
The rules for root hierarchy:
|
||||||
|
|
||||||
- lsp workspace folders
|
- lsp workspace folders
|
||||||
- lsp root_dir
|
- lsp root_dir
|
||||||
- root pattern of filename of the current buffer
|
- root pattern of filename of the current buffer
|
||||||
@ -415,14 +414,15 @@ The rules for root hierarchy:
|
|||||||
<summary>Example folder structure for custom prompt</summary>
|
<summary>Example folder structure for custom prompt</summary>
|
||||||
|
|
||||||
If you have the following structure:
|
If you have the following structure:
|
||||||
```bash
|
|
||||||
|
```bash
|
||||||
.
|
.
|
||||||
├── .git/
|
├── .git/
|
||||||
├── typescript.planning.avanterules
|
├── typescript.planning.avanterules
|
||||||
├── snippets.editing.avanterules
|
├── snippets.editing.avanterules
|
||||||
└── src/
|
└── src/
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
- `typescript.planning.avanterules` will be used for `planning` mode
|
- `typescript.planning.avanterules` will be used for `planning` mode
|
||||||
- `snippets.editing.avanterules`` will be used for `editing` mode
|
- `snippets.editing.avanterules`` will be used for `editing` mode
|
||||||
@ -434,7 +434,6 @@ If you have the following structure:
|
|||||||
>
|
>
|
||||||
> `*.avanterules` is a jinja template file, in which will be rendered using [minijinja](https://github.com/mitsuhiko/minijinja). See [templates](https://github.com/yetone/avante.nvim/blob/main/lua/avante/templates) for example on how to extend current templates.
|
> `*.avanterules` is a jinja template file, in which will be rendered using [minijinja](https://github.com/mitsuhiko/minijinja). See [templates](https://github.com/yetone/avante.nvim/blob/main/lua/avante/templates) for example on how to extend current templates.
|
||||||
|
|
||||||
|
|
||||||
## TODOs
|
## TODOs
|
||||||
|
|
||||||
- [x] Chat with current file
|
- [x] Chat with current file
|
||||||
@ -461,15 +460,15 @@ See [wiki](https://github.com/yetone/avante.nvim/wiki) for more recipes and tric
|
|||||||
|
|
||||||
We would like to express our heartfelt gratitude to the contributors of the following open-source projects, whose code has provided invaluable inspiration and reference for the development of avante.nvim:
|
We would like to express our heartfelt gratitude to the contributors of the following open-source projects, whose code has provided invaluable inspiration and reference for the development of avante.nvim:
|
||||||
|
|
||||||
| Nvim Plugin | License | Functionality | Location |
|
| Nvim Plugin | License | Functionality | Location |
|
||||||
| --- | --- | --- | --- |
|
| --------------------------------------------------------------------- | ------------------ | ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| [git-conflict.nvim](https://github.com/akinsho/git-conflict.nvim) | No License | Diff comparison functionality | [lua/avante/diff.lua](https://github.com/yetone/avante.nvim/blob/main/lua/avante/diff.lua) |
|
| [git-conflict.nvim](https://github.com/akinsho/git-conflict.nvim) | No License | Diff comparison functionality | [lua/avante/diff.lua](https://github.com/yetone/avante.nvim/blob/main/lua/avante/diff.lua) |
|
||||||
| [ChatGPT.nvim](https://github.com/jackMort/ChatGPT.nvim) | Apache 2.0 License | Calculation of tokens count | [lua/avante/utils/tokens.lua](https://github.com/yetone/avante.nvim/blob/main/lua/avante/utils/tokens.lua) |
|
| [ChatGPT.nvim](https://github.com/jackMort/ChatGPT.nvim) | Apache 2.0 License | Calculation of tokens count | [lua/avante/utils/tokens.lua](https://github.com/yetone/avante.nvim/blob/main/lua/avante/utils/tokens.lua) |
|
||||||
| [img-clip.nvim](https://github.com/HakonHarnes/img-clip.nvim) | MIT License | Clipboard image support | [lua/avante/clipboard.lua](https://github.com/yetone/avante.nvim/blob/main/lua/avante/clipboard.lua) |
|
| [img-clip.nvim](https://github.com/HakonHarnes/img-clip.nvim) | MIT License | Clipboard image support | [lua/avante/clipboard.lua](https://github.com/yetone/avante.nvim/blob/main/lua/avante/clipboard.lua) |
|
||||||
| [copilot.lua](https://github.com/zbirenbaum/copilot.lua) | MIT License | Copilot support | [lua/avante/providers/copilot.lua](https://github.com/yetone/avante.nvim/blob/main/lua/avante/providers/copilot.lua) |
|
| [copilot.lua](https://github.com/zbirenbaum/copilot.lua) | MIT License | Copilot support | [lua/avante/providers/copilot.lua](https://github.com/yetone/avante.nvim/blob/main/lua/avante/providers/copilot.lua) |
|
||||||
| [jinja.vim](https://github.com/HiPhish/jinja.vim) | MIT License | Template filetype support | [syntax/jinja.vim](https://github.com/yetone/avante.nvim/blob/main/syntax/jinja.vim) |
|
| [jinja.vim](https://github.com/HiPhish/jinja.vim) | MIT License | Template filetype support | [syntax/jinja.vim](https://github.com/yetone/avante.nvim/blob/main/syntax/jinja.vim) |
|
||||||
| [codecompanion.nvim](https://github.com/olimorris/codecompanion.nvim) | MIT License | Secrets logic support | [lua/avante/providers/init.lua](https://github.com/yetone/avante.nvim/blob/main/lua/avante/providers/init.lua) |
|
| [codecompanion.nvim](https://github.com/olimorris/codecompanion.nvim) | MIT License | Secrets logic support | [lua/avante/providers/init.lua](https://github.com/yetone/avante.nvim/blob/main/lua/avante/providers/init.lua) |
|
||||||
| [aider](https://github.com/paul-gauthier/aider) | Apache 2.0 License | Planning mode user prompt | [lua/avante/templates/planning.avanterules](https://github.com/yetone/avante.nvim/blob/main/lua/avante/templates/planning.avanterules) |
|
| [aider](https://github.com/paul-gauthier/aider) | Apache 2.0 License | Planning mode user prompt | [lua/avante/templates/planning.avanterules](https://github.com/yetone/avante.nvim/blob/main/lua/avante/templates/planning.avanterules) |
|
||||||
|
|
||||||
The high quality and ingenuity of these projects' source code have been immensely beneficial throughout our development process. We extend our sincere thanks and respect to the authors and contributors of these projects. It is the selfless dedication of the open-source community that drives projects like avante.nvim forward.
|
The high quality and ingenuity of these projects' source code have been immensely beneficial throughout our development process. We extend our sincere thanks and respect to the authors and contributors of these projects. It is the selfless dedication of the open-source community that drives projects like avante.nvim forward.
|
||||||
|
|
||||||
|
@ -175,6 +175,32 @@ M.refresh = function(opts)
|
|||||||
sidebar:render(opts)
|
sidebar:render(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param opts? AskOptions
|
||||||
|
M.focus = function(opts)
|
||||||
|
opts = opts or {}
|
||||||
|
local sidebar = require("avante").get()
|
||||||
|
if not sidebar then return end
|
||||||
|
|
||||||
|
local curbuf = vim.api.nvim_get_current_buf()
|
||||||
|
local curwin = vim.api.nvim_get_current_win()
|
||||||
|
|
||||||
|
if sidebar:is_open() then
|
||||||
|
if curbuf == sidebar.input.bufnr then
|
||||||
|
if sidebar.code.winid and sidebar.code.winid ~= curwin then vim.api.nvim_set_current_win(sidebar.code.winid) end
|
||||||
|
elseif curbuf == sidebar.result.bufnr then
|
||||||
|
if sidebar.code.winid and sidebar.code.winid ~= curwin then vim.api.nvim_set_current_win(sidebar.code.winid) end
|
||||||
|
else
|
||||||
|
if sidebar.input.winid and sidebar.input.winid ~= curwin then
|
||||||
|
vim.api.nvim_set_current_win(sidebar.input.winid)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if sidebar.code.winid then vim.api.nvim_set_current_win(sidebar.code.winid) end
|
||||||
|
sidebar:open(opts)
|
||||||
|
if sidebar.input.winid then vim.api.nvim_set_current_win(sidebar.input.winid) end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return setmetatable(M, {
|
return setmetatable(M, {
|
||||||
__index = function(t, k)
|
__index = function(t, k)
|
||||||
local module = require("avante")
|
local module = require("avante")
|
||||||
|
@ -144,6 +144,7 @@ Respect and use existing conventions, libraries, etc that are already present in
|
|||||||
ask = "<leader>aa",
|
ask = "<leader>aa",
|
||||||
edit = "<leader>ae",
|
edit = "<leader>ae",
|
||||||
refresh = "<leader>ar",
|
refresh = "<leader>ar",
|
||||||
|
focus = "<leader>af",
|
||||||
toggle = {
|
toggle = {
|
||||||
default = "<leader>at",
|
default = "<leader>at",
|
||||||
debug = "<leader>ad",
|
debug = "<leader>ad",
|
||||||
|
@ -77,6 +77,7 @@ H.commands = function()
|
|||||||
{ desc = "avante: edit selected block", nargs = "*" }
|
{ desc = "avante: edit selected block", nargs = "*" }
|
||||||
)
|
)
|
||||||
cmd("Refresh", function() require("avante.api").refresh() end, { desc = "avante: refresh windows" })
|
cmd("Refresh", function() require("avante.api").refresh() end, { desc = "avante: refresh windows" })
|
||||||
|
cmd("Focus", function() require("avante.api").focus() end, { desc = "avante: switch focus windows" })
|
||||||
cmd("Build", function(opts)
|
cmd("Build", function(opts)
|
||||||
local args = {}
|
local args = {}
|
||||||
for _, arg in ipairs(opts.fargs) do
|
for _, arg in ipairs(opts.fargs) do
|
||||||
@ -113,6 +114,7 @@ H.keymaps = function()
|
|||||||
)
|
)
|
||||||
vim.keymap.set("v", "<Plug>(AvanteEdit)", function() require("avante.api").edit() end, { noremap = true })
|
vim.keymap.set("v", "<Plug>(AvanteEdit)", function() require("avante.api").edit() end, { noremap = true })
|
||||||
vim.keymap.set("n", "<Plug>(AvanteRefresh)", function() require("avante.api").refresh() end, { noremap = true })
|
vim.keymap.set("n", "<Plug>(AvanteRefresh)", function() require("avante.api").refresh() end, { noremap = true })
|
||||||
|
vim.keymap.set("n", "<Plug>(AvanteFocus)", function() require("avante.api").focus() end, { noremap = true })
|
||||||
vim.keymap.set("n", "<Plug>(AvanteBuild)", function() require("avante.api").build() end, { noremap = true })
|
vim.keymap.set("n", "<Plug>(AvanteBuild)", function() require("avante.api").build() end, { noremap = true })
|
||||||
vim.keymap.set("n", "<Plug>(AvanteToggle)", function() M.toggle() end, { noremap = true })
|
vim.keymap.set("n", "<Plug>(AvanteToggle)", function() M.toggle() end, { noremap = true })
|
||||||
vim.keymap.set("n", "<Plug>(AvanteToggleDebug)", function() M.toggle.debug() end)
|
vim.keymap.set("n", "<Plug>(AvanteToggleDebug)", function() M.toggle.debug() end)
|
||||||
@ -146,6 +148,13 @@ H.keymaps = function()
|
|||||||
function() require("avante.api").refresh() end,
|
function() require("avante.api").refresh() end,
|
||||||
{ desc = "avante: refresh" }
|
{ desc = "avante: refresh" }
|
||||||
)
|
)
|
||||||
|
Utils.safe_keymap_set(
|
||||||
|
"n",
|
||||||
|
Config.mappings.focus,
|
||||||
|
function() require("avante.api").focus() end,
|
||||||
|
{ desc = "avante: focus" }
|
||||||
|
)
|
||||||
|
|
||||||
Utils.safe_keymap_set("n", Config.mappings.toggle.default, function() M.toggle() end, { desc = "avante: toggle" })
|
Utils.safe_keymap_set("n", Config.mappings.toggle.default, function() M.toggle() end, { desc = "avante: toggle" })
|
||||||
Utils.safe_keymap_set(
|
Utils.safe_keymap_set(
|
||||||
"n",
|
"n",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user