codesnap.nvim icon indicating copy to clipboard operation
codesnap.nvim copied to clipboard

[Feat] allow no region selection in CodeSnapHighlight

Open sarahsturgeon opened this issue 8 months ago • 3 comments

This PR simply allows users to continue through the CodeSnapHighlight popup buffer without selecting a visual region.

Why

Personally, I want to use this because I want to bind a single "make a picture of this code" keybind, and may sometimes want to highlight a specific chunk of that code. Otherwise I'd like to just make a picture of the region I initially selected.

CodeSnapHighlight would work perfectly for me, if it could support not highlighting, if desired.

How

The only change I made here was binding the highlight callback to <CR> in both visual and normal mode. The rest of the highlight code handles this appropriately, so it "just works".

Details

I used the higher-level vim.keymap.set API because it allows us to assign the same keybind to multiple modes. This is just a convenience thing, so we don't have to replicate or complicate the :lua stuff that runs.

If there's a reason why we need to use vim.api.nvim_buf_set_keymap, I can modify it to do that instead.

Demo

With visual region selected

image

Without visual region selected

image

sarahsturgeon avatar May 06 '25 18:05 sarahsturgeon

@sarahsturgeon Awesome work! Can you add to the document?

mistricky avatar May 08 '25 13:05 mistricky

@sarahsturgeon Awesome work! Can you add to the document?

Sure! Where would you like me to do that?

sarahsturgeon avatar May 09 '25 21:05 sarahsturgeon

@sarahsturgeon you can add it to the "Highlight code block" section in README

mistricky avatar May 11 '25 06:05 mistricky