Skip to content

Commit

Permalink
fix: only cache remote image urls, fixes same remote image in multipl…
Browse files Browse the repository at this point in the history
…e splits
  • Loading branch information
3rd committed Jun 30, 2023
1 parent 2c98c7c commit 1738f08
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ local api = require("image")

local image = api.from_file("path/to/image.png", {
id = "my_image_id", -- optional, defaults to a random string
window = 1000, -- optional, binds image to the window and its bounds
buffer = 1000, -- optional, binds image to buffer
window = 1000, -- optional, binds image to a window and its bounds
buffer = 1000, -- optional, binds image to a buffer (paired with window binding)
with_virtual_padding = true, -- optional, pads vertically with extmarks
...geometry, -- optional, { x, y, width, height }
})
Expand Down
6 changes: 4 additions & 2 deletions lua/image/image.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ end
---@param state State
local from_url = function(url, options, callback, state)
if state.remote_cache[url] then
callback(state.remote_cache[url])
local image = create_image(state.remote_cache[url], options, state)
callback(image)
return
end

Expand Down Expand Up @@ -184,9 +185,10 @@ local from_url = function(url, options, callback, state)
return
end

state.remote_cache[url] = tmp_path

vim.defer_fn(function()
local image = create_image(tmp_path, options, state)
state.remote_cache[url] = image
callback(image)
end, 0)
end)
Expand Down
2 changes: 1 addition & 1 deletion lua/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
---@field options Options
---@field images { [string]: Image }
---@field extmarks_namespace any
---@field remote_cache { [string]: Image }
---@field remote_cache { [string]: string }

---@class MarkdownIntegrationOptions
---@field enabled boolean
Expand Down

0 comments on commit 1738f08

Please sign in to comment.