Skip to content

Commit 54e3fc8

Browse files
committed
menu test
1 parent 79aa87b commit 54e3fc8

4 files changed

Lines changed: 358 additions & 0 deletions

File tree

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88

99
- **Open files in the browser**: Quickly open the current file in your remote Git repository's web interface.
1010
- **Line and Range Support**: Supports opening specific lines or ranges, including multiline selections from visual mode.
11+
- **Right-Click Menu**: Optional context menu with all browsher actions (requires [nvzone/menu](https://github.com/nvzone/menu)).
1112
- **Customizable providers**: Support for GitHub, GitLab, Sourcehut, and the ability to specify custom git web interfaces.
1213
- **Custom open commands**: Specify custom commands to open URLs (e.g., use a specific browser).
1314

1415
# 📦 Installation
1516
Using [lazy.nvim](https://github.com/folke/lazy.nvim)
1617

18+
## Basic Installation
19+
1720
```lua
1821
{
1922
'claydugo/browsher.nvim',
@@ -24,6 +27,35 @@ Using [lazy.nvim](https://github.com/folke/lazy.nvim)
2427
end
2528
}
2629
```
30+
31+
## Installation with Right-Click Menu
32+
33+
For a full-featured right-click menu interface, install [nvzone/menu](https://github.com/nvzone/menu) separately and enable the menu feature:
34+
35+
```lua
36+
-- Add menu dependencies (optional)
37+
{ "nvzone/volt", lazy = true },
38+
{ "nvzone/menu", lazy = true },
39+
40+
-- Configure browsher with menu enabled
41+
{
42+
'claydugo/browsher.nvim',
43+
event = "VeryLazy",
44+
config = function()
45+
require('browsher').setup({
46+
enable_menu = true,
47+
menu_keybindings = {
48+
keyboard = "<leader>bm", -- Open menu with keyboard
49+
mouse = true, -- Enable right-click menu
50+
},
51+
})
52+
end
53+
}
54+
```
55+
56+
> [!NOTE]
57+
> The menu feature is completely optional. If `enable_menu = true` but the menu dependencies aren't installed, browsher will display a warning and continue working normally with the standard command interface.
58+
2759
> [!IMPORTANT]
2860
> Please submit a Pull Request and add to this section if you have worked through installation instructions for other plugin managers!
2961
@@ -44,6 +76,15 @@ require("browsher").setup({
4476
commit_length = nil,
4577
--- Allow line numbers with uncommitted changes.
4678
allow_line_numbers_with_uncommitted_changes = false,
79+
--- Enable right-click menu integration using nvzone/menu
80+
enable_menu = false,
81+
--- Custom keybindings for the menu (when enable_menu is true)
82+
menu_keybindings = {
83+
--- Keybinding for opening menu with keyboard
84+
keyboard = "<leader>bm",
85+
--- Enable right-click mouse support
86+
mouse = true,
87+
},
4788
--- Command to open URLs (e.g., 'firefox').
4889
--- If this is a single character, it will be interpreted as a vim register
4990
--- instead. For example, to copy the url to your OS clipboard instead of
@@ -106,6 +147,8 @@ vim.api.nvim_set_keymap('v', '<leader>B', ":'<,'>Browsher tag<CR>gv", { noremap
106147

107148
# 🚀 Usage
108149

150+
## Command Line
151+
109152
Use the `:Browsher` command to open the current file in your browser:
110153

111154
```
@@ -159,6 +202,27 @@ Select lines in visual mode and run:
159202
:Browsher
160203
```
161204

205+
## Right-Click Menu
206+
207+
When the menu feature is enabled, you can:
208+
209+
- Press `<leader>bm` (or your custom keyboard binding) to open the menu in normal or visual mode
210+
- **Visual mode**: Select lines and right-click to open the context menu with selection-specific options
211+
212+
The menu provides these options:
213+
214+
- **📍 Open at Commit** - Submenu with HEAD, HEAD~1, HEAD~2, etc. (up to HEAD~5)
215+
- **🌿 Open at Branch** - Open file at current branch
216+
- **🏷️ Open at Latest Tag** - Open file at latest tag
217+
- **🏠 Open Repository Root** - Open repository homepage
218+
- **📋 Copy URL (Commit)** - Submenu to copy URL for specific commits
219+
- **📋 Copy URL (Branch)** - Copy branch URL to clipboard
220+
221+
Navigation:
222+
- `h` and `l` - Move between windows
223+
- `q` - Close menu
224+
- Press keybind or scroll and press Enter to execute
225+
162226
# ⚠️ Notes
163227

164228
* **Uncommitted Changes**: If the current file has uncommitted changes, line numbers may not correspond to what's on the remote repository. By default, line numbers are omitted when there are uncommitted changes unless `allow_line_numbers_with_uncommitted_changes` is set to true.

lua/browsher/config.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ M.options = {
1414
open_cmd = nil,
1515
--- Allow line numbers with uncommitted changes.
1616
allow_line_numbers_with_uncommitted_changes = false,
17+
--- Enable right-click menu integration using nvzone/menu
18+
enable_menu = false,
19+
--- Custom keybindings for the menu (when enable_menu is true)
20+
menu_keybindings = {
21+
--- Keybinding for opening menu with keyboard
22+
keyboard = "<leader>bm",
23+
--- Enable right-click mouse support
24+
mouse = true,
25+
},
1726
--- Custom providers for building URLs.
1827
---
1928
--- Each provider is a table with the following keys:

lua/browsher/init.lua

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,48 @@ end
197197
---@param user_options table User-specified options.
198198
function M.setup(user_options)
199199
config.setup(user_options)
200+
201+
-- Setup menu keybindings if enabled and menu plugin is available
202+
if config.options.enable_menu then
203+
local has_menu = pcall(require, "menu")
204+
if has_menu then
205+
M.setup_menu()
206+
else
207+
utils.notify(
208+
"Menu feature enabled but nvzone/menu not found. "
209+
.. "Install nvzone/volt and nvzone/menu to use the menu feature.",
210+
vim.log.levels.WARN
211+
)
212+
end
213+
end
214+
end
215+
216+
--- Setup menu keybindings
217+
function M.setup_menu()
218+
local menu_config = config.options.menu_keybindings
219+
220+
-- Setup keyboard binding (works in both normal and visual mode)
221+
if menu_config.keyboard then
222+
vim.keymap.set({ "n", "v" }, menu_config.keyboard, function()
223+
require("browsher.menu").open()
224+
end, { noremap = true, silent = true, desc = "Open Browsher menu" })
225+
end
226+
227+
-- Setup mouse right-click binding (only in visual mode to preserve default right-click in normal mode)
228+
if menu_config.mouse then
229+
vim.keymap.set("v", "<RightMouse>", function()
230+
-- Position cursor at mouse click
231+
vim.cmd('normal! "\\<RightMouse>"')
232+
233+
-- Delete old menus if they exist
234+
pcall(function()
235+
require("menu.utils").delete_old_menus()
236+
end)
237+
238+
-- Open browsher menu
239+
require("browsher.menu").open({ mouse = true })
240+
end, { noremap = true, silent = true, desc = "Open Browsher menu at mouse" })
241+
end
200242
end
201243

202244
return M

0 commit comments

Comments
 (0)