3rd / image.nvim

đŸ–Œïž Bringing images to Neovim.
MIT License
1.16k stars 51 forks source link

[Bug]: Misplacement of pictures #174

Open xuwei152 opened 5 months ago

xuwei152 commented 5 months ago

The position of pictures is not corrected, shown as pic below Clip_2024-05-29_16-42-17

The plugin is install with lazy.nvim with the configuration shown below

{
    "3rd/image.nvim",
    ft = { "markdown" },
    dependencies = {
      {
        "nvim-treesitter/nvim-treesitter",
        build = ":TSUpdate",
        config = function()
          require("nvim-treesitter.configs").setup({
            ensure_installed = { "markdown" },
            highlight = { enable = true },
          })
        end,
      },
    },
    config = function()
      require("image").setup({
        backend = "kitty",
        integrations = {
          markdown = {
            enabled = true,
            clear_in_insert_mode = true,
            download_remote_images = true,
            only_render_image_at_cursor = true,
            filetypes = { "markdown", "vimwiki" }, -- markdown extensions (ie. quarto) can go here
          },
          neorg = {
            enabled = true,
            clear_in_insert_mode = false,
            download_remote_images = true,
            only_render_image_at_cursor = false,
            filetypes = { "norg" },
          },
        },
        max_width = nil,
        max_height = nil,
        max_width_window_percentage = nil,
        max_height_window_percentage = 50,
        kitty_method = "normal",
      })
    end
  },

Environment:

3rd commented 5 months ago

Hey, do you use any kind of tab bar / breadcrumbs thing?

xuwei152 commented 5 months ago

Yes, I have installed lualine.nvim. Other loaded plugins are listed as follows:


  Total: 105 plugins

  Loaded (80)
    ● alpha-nvim 15.92ms îȘ† VimEnter
    ● bigfile.nvim 52.18ms îȘ† BufReadPre
    ● bufferline.nvim 25.05ms îȘ† User FileOpened
    ● cmp-buffer 21.45ms  nvim-cmp
    ● cmp-bufname 29.38ms îȘ† VeryLazy
    ● cmp-cmdline 23.37ms  nvim-cmp
    ● cmp-dictionary 21.95ms îȘ† VeryLazy
    ● cmp-fuzzy-path 174.08ms îȘ† VeryLazy
    ● cmp-git 23.76ms îȘ† InsertEnter
    ● cmp-latex-symbols 36.26ms  markdown
    ● cmp-nvim-lsp 17.28ms  nvim-cmp
    ● cmp-omni 16.59ms îȘ† InsertEnter
    ● cmp-path 19.76ms  nvim-cmp
    ● cmp_luasnip 33.53ms  nvim-cmp
    ● coc.nvim 80.99ms îȘ† InsertEnter
    ● Comment.nvim 16.46ms îȘ† User FileOpened
    ● fittencode.nvim 61.95ms îȘ† InsertEnter
    ● friendly-snippets 22.39ms  LuaSnip
    ● fuzzy.nvim 1.73ms  cmp-fuzzy-path
    ● fzf 6.24ms  fzf.vim
    ● fzf.vim 13.08ms  start
    ● gitsigns.nvim 22.86ms îȘ† User FileOpened
    ● hop.nvim 25.39ms  HopChar1
    ● http.nvim 11.71ms îȘ† VeryLazy
    ● image.nvim 174.54ms  markdown
    ● indent-blankline.nvim 13.3ms îȘ† User FileOpened
    ● latex-unicoder.vim 1.48ms  markdown
    ● latex.nvim 0.62ms  markdown
    ● lazy.nvim 34.75ms ï„Ą init.lua
    ● leap.nvim 24.25ms îȘ† VeryLazy
    ● lspkind.nvim 4.28ms  start
    ● ltex-client.nvim 14.39ms îȘ† VeryLazy
    ● lualine.nvim 69.13ms îȘ† VimEnter
    ● LuaSnip 171.2ms ó°ą± luasnip.loaders.from_lua  LuaSnip
    ● mason-lspconfig.nvim 28.7ms  nvim-lspconfig
    ● mason.nvim 15.64ms  mason-lspconfig.nvim
    ● mkdnflow.nvim 24.25ms  markdown
    ● nlsp-settings.nvim 1.32ms  nvim-lspconfig
    ● none-ls.nvim 1.07ms ó°ą± null-ls.rpc  none-ls.nvim
    ● nvim-autopairs 25.8ms îȘ† InsertEnter
    ● nvim-cmp 143.54ms  cmp-fuzzy-path
    ● nvim-lastplace 12.53ms îȘ† BufRead
    ● nvim-lspconfig 34.92ms  nvim-texis
    ● nvim-markdown 7.33ms  markdown
    ● nvim-navic 10.42ms îȘ† User FileOpened
    ● nvim-neoclip.lua 22.76ms îȘ† VeryLazy
    ● nvim-texis 41.58ms  start
    ● nvim-treesitter 47.54ms  bigfile.nvim
    ● nvim-treesitter-context 63.22ms îȘ† VeryLazy
    ● nvim-ts-context-commentstring 11.58ms ó°ą± ts_context_commentstring.integrations.comment_nvim ï„Ą /home/xuwei/Trash/lunarvim/lvim/lua/lvim/core/comment.lua
    ● nvim-ufo 22.12ms îȘ† VeryLazy
    ● nvim-web-devicons 1.6ms ó°ą± nvim-web-devicons ï„Ą /home/xuwei/Trash/lunarvim/lvim/lua/lvim/core/breadcrumbs.lua
    ● nvim-window 16.98ms îȘ† VeryLazy
    ● nvim_context_vt 3.29ms îȘ† VeryLazy
    ● onedarker.nvim 60.71ms  start
    ● plenary.nvim 1.76ms ó°ą± plenary.path  telescope.nvim
    ● promise-async 10.98ms  nvim-ufo
    ● rainbow-delimiters.nvim 24.92ms  start
    ● snippet-converter.nvim 42.66ms îȘ† VeryLazy
    ● spelunker.vim 18.91ms îȘ† VeryLazy
    ● tabular 38.35ms îȘ† InsertEnter
    ● telescope-bibtex.nvim 41.56ms îȘ† VeryLazy
    ● telescope-fzf-native.nvim 11.71ms  telescope.nvim
    ● telescope-luasnip.nvim 201.28ms îȘ† VeryLazy
    ● telescope.nvim 118.11ms ó°ą± telescope  telescope-luasnip.nvim
    ● todo-comments.nvim 25.2ms îȘ† VeryLazy
    ● trouble.nvim 1.7ms ó°ą± trouble ï„Ą lua
    ● vim-conceal 0.76ms îȘ† VeryLazy
    ● vim-cursorword 29.55ms îȘ† VeryLazy
    ● vim-custom-surround 2.14ms îȘ† VeryLazy
    ● vim-devicons 4.91ms îȘ† VeryLazy
    ● vim-diminactive 2.89ms îȘ† VeryLazy
    ● vim-easymotion 5.4ms îȘ† InsertEnter
    ● vim-illuminate 15.81ms îȘ† User FileOpened
    ● vim-surround 2.22ms îȘ† InsertEnter
    ● vim-tmux-navigator 1.96ms îȘ† VeryLazy
    ● vim-zoom 3.04ms îȘ† VeryLazy
    ● vimtex 7.07ms  start
    ● which-key.nvim 55.8ms îȘ† VeryLazy
    ● zoomwintab.vim 2.11ms îȘ† VeryLazy
MikeLemo1 commented 5 months ago

Maybe an option to give the image an initial global rendering offset would be a good idea it just needs an offset of 2 columns down to be "corrected" assuming because of the barbar + breadcrums extension, also The autocmd of the image render at buffer change doesn't work well for me as I have to close and reopen nvim to have the images refreshed in md files, so maybe exposing a function to refresh all images on scene'd useful as well,

BTW It maybe because I don't have sufficient knowledge in lua but how do to access each individual image rendered in markdown? (in what array / through what method etc...

3rd commented 5 months ago

Yes, will add a global offset option, will also try to monitor when something like barbar mounts, the issue if I remember was that it's not there when we check for it.

The integration (https://github.com/3rd/image.nvim/blob/master/lua/image/integrations/markdown.lua) extracts the and creates images, you can use .get_images() to query them: https://github.com/3rd/image.nvim/blob/a2a0849e0b3dbed90f9283603cedb683bda5d4d1/lua/image/init.lua#L411

MikeLemo1 commented 5 months ago

BTW a quick and dirty way to offset the image 2 column down is to go to "~/.local/share/nvim/lazy/image.nvim/lua/image/utils/offsets.lua" and change line 22 from: local y = 0 to local y = 2

Altough is mostly corrected the problem it requires a new line of spacing in order not to obstruct the content belowe it which is covers half a column below it more than then size of the picture after the 2 column offset but now it's workable 1 extra column that's also serve as spacing is acceptable for now, Now displaying svg's I noticed the rendering doesn't take into account the opacity value for some reason... any quick fix for that? or that requires diving into the image drivers bit?

xuwei152 commented 5 months ago

It is quite weird that some of the pictures are placed properly. Clip_2024-06-10_21-53-27

Therefore, the modification of the offset cannot fix the problem.

MikeLemo1 commented 5 months ago

It is quite weird that some of the pictures are placed properly. Clip_2024-06-10_21-53-27

Therefore, the modification of the offset cannot fix the problem.

Are there specific image files you have that display properly?

xuwei152 commented 5 months ago

Yes, some images are displayed properly. One of them is shown as below.

It is quite weird that some of the pictures are placed properly. Clip_2024-06-10_21-53-27

Therefore, the modification of the offset cannot fix the problem.

I have moved the image that are displayed improperly to other places and then it is placed correctly. I guess the problem is related to text surrounding the image.

3rd commented 5 months ago

BTW a quick and dirty way to offset the image 2 column down is to go to "~/.local/share/nvim/lazy/image.nvim/lua/image/utils/offsets.lua" and change line 22 from: local y = 0 to local y = 2

Altough is mostly corrected the problem it requires a new line of spacing in order not to obstruct the content belowe it which is covers half a column below it more than then size of the picture after the 2 column offset but now it's workable 1 extra column that's also serve as spacing is acceptable for now, Now displaying svg's I noticed the rendering doesn't take into account the opacity value for some reason... any quick fix for that? or that requires diving into the image drivers bit?

ImageMagick is the issue for transparency, I'm working on a complete replacement for it.

3rd commented 5 months ago

Yes, some images are displayed properly. One of them is shown as below.

It is quite weird that some of the pictures are placed properly. Clip_2024-06-10_21-53-27

Therefore, the modification of the offset cannot fix the problem.

I have moved the image that are displayed improperly to other places and then it is placed correctly. I guess the problem is related to text surrounding the image.

I think in all cases it's caused by tab bar handling, will look into it.

sudo-burger commented 4 months ago

I have a similar issue, apparently caused by concealed wrapped lines. The attached markdown file should be a minimal example (you must ensure that the width of the terminal is less than the length of the URLs).

Screenshot 2024-07-05 at 21 41 41

images.md