Skip to content

Commit

Permalink
Merge branch 'main' of github.com:jmbuhr/quarto-nvim-kickstarter
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbuhr committed Apr 15, 2024
2 parents d63759b + 89bbd99 commit 1b0141b
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 76 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# Changelog

## [3.6.0](https://github.com/jmbuhr/quarto-nvim-kickstarter/compare/v3.5.0...v3.6.0) (2024-04-13)


### Features

* preview image under cursor with <leader>io ([a89dc45](https://github.com/jmbuhr/quarto-nvim-kickstarter/commit/a89dc45106d687213031c7df3851ed79f1324324))

## [3.5.0](https://github.com/jmbuhr/quarto-nvim-kickstarter/compare/v3.4.0...v3.5.0) (2024-04-12)


### Features

* disable eob fill chars for better png previews ([12363f0](https://github.com/jmbuhr/quarto-nvim-kickstarter/commit/12363f0555845b1d5b5ba4549b58a96a2fa93e8c))


### Bug Fixes

* don't prompt for ipython or R exit/save ([a213e66](https://github.com/jmbuhr/quarto-nvim-kickstarter/commit/a213e66fbadfaa43b9fc2f011185498ba95d409e))
* **keymap:** toggle dark/light ([21d554e](https://github.com/jmbuhr/quarto-nvim-kickstarter/commit/21d554e3f9599ab40be3d702a49f7a441b9bbb26))


### Performance Improvements

* **startup:** only load image.nvim for certain ft ([8377fd8](https://github.com/jmbuhr/quarto-nvim-kickstarter/commit/8377fd8833c293bf2ed6583db99a7932bb1fef9a))

## [3.4.0](https://github.com/jmbuhr/quarto-nvim-kickstarter/compare/v3.3.0...v3.4.0) (2024-04-11)


Expand Down
2 changes: 1 addition & 1 deletion lua/config/keymap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ wk.register({
},
},
i = {
name = '[i]nsert',
name = '[i]mage',
},
l = {
name = '[l]anguage/lsp',
Expand Down
3 changes: 1 addition & 2 deletions lua/config/lazy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ require('lazy').setup('plugins', {
},
},
change_detection = {
-- automatically check for config file changes and reload the ui
enabled = true,
notify = false, -- get a notification when changes are found
notify = false,
},
})
68 changes: 0 additions & 68 deletions lua/config/wip/focus-image.lua

This file was deleted.

61 changes: 56 additions & 5 deletions lua/plugins/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ return {
-- sudo apt install liblua5.1-0-dev
-- sudo apt installl luajit

require('image').setup {
local image = require 'image'
image.setup {
backend = 'kitty',
integrations = {
markdown = {
Expand All @@ -341,13 +342,63 @@ return {
filetypes = { 'markdown', 'vimwiki', 'quarto' },
},
},
-- auto show/hide images when the editor gains/looses focus
editor_only_render_when_focused = false,
-- toggles images when windows are overlapped
window_overlap_clear_enabled = false,
-- auto show/hide images in the correct Tmux window (needs visual-activity off)
window_overlap_clear_enabled = true,
tmux_show_only_in_active_window = true,
max_width = nil,
max_height = nil,
max_width_window_percentage = nil,
max_height_window_percentage = 30,
kitty_method = 'normal',
}

local function get_image_at_cursor(buf)
local images = image.get_images { buffer = buf }
local row = vim.api.nvim_win_get_cursor(0)[1]
for _, img in ipairs(images) do
if img.geometry ~= nil and img.geometry.y == row then
local og_max_height = img.global_state.options.max_height_window_percentage
img.global_state.options.max_height_window_percentage = nil
return img, og_max_height
end
end
return nil
end

local create_preview_window = function(img, og_max_height)
local buf = vim.api.nvim_create_buf(false, true)
local win_width = vim.api.nvim_get_option_value('columns', {})
local win_height = vim.api.nvim_get_option_value('lines', {})
local win = vim.api.nvim_open_win(buf, true, {
relative = 'editor',
style = 'minimal',
width = win_width,
height = win_height,
row = 0,
col = 0,
zindex = 1000,
})
vim.keymap.set('n', 'q', function()
vim.api.nvim_win_close(win, true)
img.global_state.options.max_height_window_percentage = og_max_height
end, { buffer = buf })
return { buf = buf, win = win }
end

local handle_zoom = function(bufnr)
local img, og_max_height = get_image_at_cursor(bufnr)
if img == nil then
return
end

local preview = create_preview_window(img, og_max_height)
image.hijack_buffer(img.path, preview.win, preview.buf)
end

vim.keymap.set('n', '<leader>io', function()
local bufnr = vim.api.nvim_get_current_buf()
handle_zoom(bufnr)
end, { buffer = true, desc = 'image [o]pen' })
end,
},
}

0 comments on commit 1b0141b

Please sign in to comment.