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

[BUG] Every first screenshot fails with "node code selected" #103

Open
willdavidow opened this issue May 9, 2024 · 8 comments
Open

[BUG] Every first screenshot fails with "node code selected" #103

willdavidow opened this issue May 9, 2024 · 8 comments

Comments

@willdavidow
Copy link

willdavidow commented May 9, 2024

Just installed the plugin and everything works fine for the most part, but it seems the first attempt always fails when trying to generate screenshots to both the clipboard or the save path.

Steps to reproduce

Open nvim and any file
Select code and attempt to generate screenshot

Result

no code is selected

Expected

Screenshot generated to either clipboard or save path

When I de-select and re-select the exact code, in the exact same way, everything works fine.. it's just that first attempt that doesn't work.

Screen.Recording.2024-05-09.at.9.20.52.AM.mov
@mistricky
Copy link
Owner

Hi @willdavidow, thx for this issue reporting, that's interesting bug but I can't reproduce on my machine.

but it seems the first attempt always fails when trying to generate screenshots to both the clipboard or the save path.

The "first attempt" refer to the first screenshot taken after first CodeSnap was installed or the first screenshot taken after opening nvim every time?

@willdavidow
Copy link
Author

The "first attempt" refer to the first screenshot taken after first CodeSnap was installed or the first screenshot taken after opening nvim every time?

It's every time after closing and reopening nvim.

@mistricky
Copy link
Owner

What version of your Neovim? If you enter command instead of use hotkey, did it works?

@DrummyFloyd
Copy link

DrummyFloyd commented May 15, 2024

i have the same behaviour upon the couple of first time , when i opend nvim ( LAZYVIM config here)

with command line it work like a charm

return {
  {
    "mistricky/codesnap.nvim",
    build = "make build_generator",
    keys = {
      { "<leader>cs", "<cmd>CodeSnap<cr>", mode = "x", desc = "Save selected code snapshot into clipboard" },
      { "<leader>cS", "<cmd>CodeSnapSave<cr>", mode = "x", desc = "Save selected code snapshot in ~/Pictures/" },
    },
    lazy = true, <= same behaviour with true or false
    opts = {
      mac_window_bar = false,
      save_path = "~/Pictures/",
      has_breadcrumbs = true,
      bg_theme = "sea",
      watermark = "",
      code_font_family = "FiraCode Nerd Font",
      has_line_number = true,
      show_workspace = false,
    },
  },
}

could be related to Lazy event ??

EDIT:
i tried on both stable 9.5 adn nightly for Neovim

@willdavidow
Copy link
Author

What version of your Neovim? If you enter command instead of use hotkey, did it works?

I'm running nvim nightly: NVIM v0.10.0-dev-3094+ge14e75099-Homebrew - updated a day or two ago.

Running the command directly does work just fine.

@try-to-fly
Copy link

try-to-fly commented May 30, 2024

I have the same issue, it seems to be a problem with nvim. After starting nvim, the return value of this command is empty. Only after the second execution does the command produce content:

vim.fn.getline("'<", "'>")

Update:
It seems that this might not be a bug with nvim after all. I executed the following command directly in the command line, and even on the first launch, it was able to correctly retrieve the selected text content.

'<,'>lua local lines = vim.fn.getline("'<", "'>"); for _, line in ipairs(lines) do print(line) end

@HugoxSaraiva
Copy link

I encountered the same issue, but it appears I've found a solution. It seems that the markers '< and >' retain values from the previous visual mode selection. When Neovim is opened, they are set to 0. You can read this for more details.

To resolve this, I simply adjusted my configuration to exit visual mode before calling CodeSnap. Executing the following command: <Esc><cmd>CodeSnap<cr>.

As this bug arises due to the plugin attempting to retrieve the last selection markers rather than the current selection, it could imply that the snapshot result consistently lags by one. However, that requires further verification.

@DrummyFloyd
Copy link

I encountered the same issue, but it appears I've found a solution. It seems that the markers '< and >' retain values from the previous visual mode selection. When Neovim is opened, they are set to 0. You can read this for more details.

To resolve this, I simply adjusted my configuration to exit visual mode before calling CodeSnap. Executing the following command: <Esc><cmd>CodeSnap<cr>.

As this bug arises due to the plugin attempting to retrieve the last selection markers rather than the current selection, it could imply that the snapshot result consistently lags by one. However, that requires further verification.

Work as expected, but for me it's kinda of a Workaround , if i check with many other keymap there is no <Esc>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants