diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b29997..6b1edce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lua/config/keymap.lua b/lua/config/keymap.lua index 2583d12..f1ca99d 100644 --- a/lua/config/keymap.lua +++ b/lua/config/keymap.lua @@ -341,7 +341,7 @@ wk.register({ }, }, i = { - name = '[i]nsert', + name = '[i]mage', }, l = { name = '[l]anguage/lsp', diff --git a/lua/config/lazy.lua b/lua/config/lazy.lua index 799e2ba..8bd6e63 100644 --- a/lua/config/lazy.lua +++ b/lua/config/lazy.lua @@ -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, }, }) diff --git a/lua/config/wip/focus-image.lua b/lua/config/wip/focus-image.lua deleted file mode 100644 index f44a990..0000000 --- a/lua/config/wip/focus-image.lua +++ /dev/null @@ -1,68 +0,0 @@ -local api = require 'image' - -M = {} - -local function get_image_at_cursor(buf) - local images = api.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 - return img - end - end - return nil -end - -M.main = function() - local cur_buf = vim.api.nvim_get_current_buf() - local image = get_image_at_cursor(cur_buf) - if image == nil then - return - end - - local width = vim.api.nvim_get_option_value('columns', {}) - local height = vim.api.nvim_get_option_value('lines', {}) - - local preview_buf = vim.api.nvim_create_buf(false, true) - local win = vim.api.nvim_open_win(preview_buf, true, { - relative = 'editor', - anchor = 'NW', - width = width, - height = height, - row = 0, - col = 0, - zindex = 300, - style = 'minimal', - }) - - -- copy original options to reset afterwards - local og_options = {} - for k, v in pairs(image.global_state.options) do - og_options[k] = v - end - - local og_extmark = image.extmark - - image.global_state.options.max_height = nil - image.global_state.options.max_width = nil - image.global_state.options.max_width_window_percentage = nil - image.global_state.options.max_height_window_percentage = nil - - for _, img in ipairs(api.get_images()) do - img:clear() - end - - vim.print(image.global_state) - - api.hijack_buffer(image.path, win, preview_buf) - - vim.keymap.set('n', 'q', function() - api.clear() - image.global_state.options = og_options - image.extmark = og_extmark - image:render() - vim.api.nvim_win_close(win, true) - end, { buffer = preview_buf }) -end - -vim.keymap.set('n', 'io', M.main, { desc = '[i]mage [o]pen' }) diff --git a/lua/plugins/ui.lua b/lua/plugins/ui.lua index 5726b7a..bffa944 100644 --- a/lua/plugins/ui.lua +++ b/lua/plugins/ui.lua @@ -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 = { @@ -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', 'io', function() + local bufnr = vim.api.nvim_get_current_buf() + handle_zoom(bufnr) + end, { buffer = true, desc = 'image [o]pen' }) end, }, }