3rd / image.nvim

🖼️ Bringing images to Neovim.
MIT License
803 stars 35 forks source link

How to toggle markdown image previews with a command? #181

Closed MikeLemo1 closed 2 weeks ago

MikeLemo1 commented 2 weeks ago

I'm trying to toggle image preview on and off in a markdown file to scan scroll it faster and I'm now sure this feature is available is it? if not i'd be helpful to know how refined / not this project is to know how to approach feature dev and bug rectification in the future

3rd commented 2 weeks ago

Hey, here's a sample for clearing / rerendering from Discord:

local api = require("image")

local bufnr = vim.api.nvim_get_current_buf()
local images = api.get_images({ buffer = bufnr })
for _, image in ipairs(images) do
  image:clear(true)
end

vim.keymap.set("n", "<leader>x", function()
  for _, image in ipairs(images) do
    image:render()
  end
end)

Will add a built-in way to toggle them, we also need to disable the integration when it's turned off.

MikeLemo1 commented 2 weeks ago
vim.keymap.set({ "n", "v" }, "<leader>pt", function()
          local bufnr = vim.api.nvim_get_current_buf()
          local images = api.get_images({ buffer = bufnr })
          for _, image in ipairs(images) do
            image:clear(true)
          end
          end, opts) 

This doesn't hide the image but just blinks it when ++\<leader>-p-t++

3rd commented 2 weeks ago

@MikeLemo1 Try this branch please: https://github.com/3rd/image.nvim/pull/182

local api = require("image")

vim.keymap.set({ "n", "v" }, "<c-c>", function()
  api.disable()
end, {})

vim.keymap.set({ "n", "v" }, "<c-x>", function()
  api.enable()
end, {})
MikeLemo1 commented 2 weeks ago

with lazy plugin manager:

{
      "3rd/image.nvim",
      branch = "feat/toggle-rendering",
    config = function()
    local api = require("image")

    vim.keymap.set({ "n", "v" }, "<leader>pc", function()
      api.disable()
    end, {})

    vim.keymap.set({ "n", "v" }, "<leader>po", function()
      api.enable()
    end, {})
    end,
}

Does the trick!

BTW Whatbout the image offset? it also might require "padding offset" as it can also be reduced one column less for more "page efficiecy"

3rd commented 2 weeks ago

Ah it's complicated, can look into it after finishing the first rewrite.