Skip to content

Commit 7585837

Browse files
authored
feat(ui): add yank register copy action (#3)
* feat(ui): add yank register copy action - add "[y] Copy to yank register" action in UI content - map "y" key to copy commit message to yank register with notification * docs(ui): update documentation for yank register support - add references to yank register in README and help docs - document new `y` keymap for copying to yank register - clarify clipboard and yank register functionality in UI descriptions - update feature lists to include yank register support Closes #123
1 parent 0f10333 commit 7585837

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A CodeCompanion extension that generates AI-powered git commit messages followin
55
## Features
66

77
- 🤖 AI-powered commit message generation using CodeCompanion's LLM adapters
8-
- 📋 Interactive UI with copy and commit options
8+
- 📋 Interactive UI with copy to clipboard and yank register options
99
- ✅ Conventional Commits specification compliance
1010
- 🔍 Automatic git repository detection
1111
- 📝 Support for both user commands and slash commands
@@ -128,8 +128,8 @@ Manages LLM interaction:
128128
Provides interactive user interface:
129129

130130
- Floating window display with markdown formatting
131-
- Interactive keyboard shortcuts (`c`, `s`, `Enter`, `q/Esc`)
132-
- Copy to clipboard functionality
131+
- Interactive keyboard shortcuts (`c`, `y`, `s`, `Enter`, `q/Esc`)
132+
- Copy to clipboard and yank register functionality
133133
- Responsive window sizing
134134

135135
### `buffer.lua`
@@ -176,10 +176,21 @@ Main extension coordinator:
176176
3. Review the generated commit message in the floating window
177177
4. Choose an action:
178178
- `c` - Copy to clipboard
179+
- `y` - Copy to yank register
179180
- `s` - Submit (commit changes)
180181
- `Enter` - Copy and close
181182
- `q/Esc` - Close without action
182183

184+
### Interactive Keymaps
185+
186+
When the floating window is displayed with the generated commit message, the following keymaps are available:
187+
188+
- **`c`** - Copy the commit message to the system clipboard (`+` register)
189+
- **`y`** - Copy the commit message to Vim's default yank register (`"` register)
190+
- **`s`** - Submit the commit message immediately (executes `git commit`)
191+
- **`Enter`** - Copy to clipboard and close the floating window
192+
- **`q` or `Esc`** - Close the floating window without taking any action
193+
183194
### GitCommit Buffer Workflow
184195
1. Stage your changes with `git add`
185196
2. Run `git commit` to open the commit buffer

doc/codecompanion-gitcommit.txt

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ analyze your staged changes and create appropriate commit messages.
3131
2. FEATURES *codecompanion-gitcommit-features*
3232

3333
• AI-powered commit message generation using CodeCompanion's LLM adapters
34-
• Interactive UI with copy and commit options
34+
• Interactive UI with copy to clipboard and yank register options
3535
• Conventional Commits specification compliance
3636
• Automatic git repository detection
3737
• Support for both user commands and slash commands
@@ -154,6 +154,7 @@ Traditional Workflow:~
154154
3. Review the generated commit message in the floating window
155155
4. Choose an action:
156156
`c` - Copy to clipboard
157+
`y` - Copy to yank register
157158
`s` - Submit (commit changes)
158159
`Enter` - Copy and close
159160
`q/Esc` - Close without action
@@ -174,6 +175,31 @@ Amend Workflow:~
174175
appropriate message
175176
6. Edit if needed and save to complete the amend
176177

178+
5.5 Interactive Keymaps *codecompanion-gitcommit-keymaps*
179+
180+
When the floating window is displayed with the generated commit message,
181+
the following keymaps are available:
182+
183+
`c` *gitcommit-keymap-c*
184+
Copy the commit message to the system clipboard. This uses the `+`
185+
register and also copies to `*` register if clipboard support is
186+
available.
187+
188+
`y` *gitcommit-keymap-y*
189+
Copy the commit message to Vim's default yank register (`"`). This
190+
allows you to paste the message using `p` or `P` commands within Vim.
191+
192+
`s` *gitcommit-keymap-s*
193+
Submit the commit message immediately. This will execute `git commit`
194+
with the generated message and close the floating window if successful.
195+
196+
`<Enter>` *gitcommit-keymap-enter*
197+
Copy the commit message to clipboard (same as `c`) and close the
198+
floating window.
199+
200+
`q` or `<Esc>` *gitcommit-keymap-q*
201+
Close the floating window without taking any action.
202+
177203
==============================================================================
178204
6. COMMANDS *codecompanion-gitcommit-commands*
179205

@@ -278,7 +304,7 @@ generator.lua~
278304
ui.lua~
279305
Provides interactive user interface including floating window display
280306
with markdown formatting, interactive keyboard shortcuts, copy to
281-
clipboard functionality, and responsive window sizing.
307+
clipboard and yank register functionality, and responsive window sizing.
282308

283309
buffer.lua~
284310
Handles gitcommit buffer integration including automatic keymap setup

lua/codecompanion/_extensions/gitcommit/generator.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,21 @@ Please only return a commit message that strictly follows the Conventional Commi
8383
4. Body (optional): use bullet points (-) to list specific changes
8484
8585
Example format:
86+
8687
feat(scope): add new feature
88+
8789
- implement X functionality
8890
- update Y module
8991
- add tests for Z
9092
93+
The message need follow this :
94+
95+
<type>(<scope>): <subject>
96+
<BLANK LINE>
97+
<body>
98+
<BLANK LINE>
99+
<footer>
100+
91101
Note: You need to answer in %s.
92102
93103
Based on the git diff provided below, generate a standardized commit message.

lua/codecompanion/_extensions/gitcommit/ui.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function UI._prepare_content(message)
5454
table.insert(content, "## Actions")
5555
table.insert(content, "")
5656
table.insert(content, "- **[c]** Copy to clipboard")
57+
table.insert(content, "- **[y]** Copy to yank register")
5758
table.insert(content, "- **[s]** Submit (commit changes)")
5859
table.insert(content, "- **[Enter]** Copy and close")
5960
table.insert(content, "- **[q/Esc]** Close")
@@ -126,12 +127,17 @@ function UI._setup_keymaps(buf, win, message, on_commit)
126127
vim.api.nvim_win_close(win, true)
127128
end, opts)
128129

129-
-- Copy to clipboard
130130
vim.keymap.set("n", "c", function()
131131
copy_to_clipboard(message)
132132
vim.notify("📋 Commit message copied to clipboard", vim.log.levels.INFO)
133133
end, opts)
134134

135+
-- Copy to yank register
136+
vim.keymap.set("n", "y", function()
137+
vim.fn.setreg('"', message)
138+
vim.notify("📝 Commit message copied to yank register", vim.log.levels.INFO)
139+
end, opts)
140+
135141
-- Submit commit
136142
vim.keymap.set("n", "s", function()
137143
local success = on_commit(message)

0 commit comments

Comments
 (0)