From c3158d774cc02523188e4ce03b4972f1ad250e9d Mon Sep 17 00:00:00 2001 From: Amanda Graven Date: Tue, 21 May 2024 13:22:22 +0200 Subject: [PATCH] Zoom with neovide scale factor if available --- init.lua | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/init.lua b/init.lua index 89d2c00..55a13f8 100644 --- a/init.lua +++ b/init.lua @@ -99,13 +99,9 @@ local zoom_notification = nil --- "Zoom" by changing gui font size --- @param delta integer function _G.zoom(delta) - local size = fn.substitute(o.guifont, [[^.*:h\([^:]*\).*$]], [[\1]], '') - size = size + delta - local guifont = fn.substitute(o.guifont, [[:h\([^:]*\)]], ':h' .. size, '') - o.guifont = guifont local properties = { - title = 'Font size', hide_from_history = true, + render = 'compact', on_close = function() zoom_notification = nil end @@ -113,7 +109,21 @@ function _G.zoom(delta) if zoom_notification ~= nil then properties.replace = zoom_notification.id end - zoom_notification = vim.notify('Changing font size to ' .. size, vim.log.levels.INFO, properties) + + local message + if vim.g.neovide_scale_factor ~= nil then + properties.title = 'Zoom' + vim.g.neovide_scale_factor = vim.g.neovide_scale_factor + (delta * 0.05) + message = 'Zoom set to ' .. vim.g.neovide_scale_factor * 100 .. '%' + else + properties.title = 'Font size' + local size = fn.substitute(o.guifont, [[^.*:h\([^:]*\).*$]], [[\1]], '') + size = size + delta + local guifont = fn.substitute(o.guifont, [[:h\([^:]*\)]], ':h' .. size, '') + o.guifont = guifont + message = 'Font size set to ' .. size + end + zoom_notification = vim.notify(message, vim.log.levels.INFO, properties) end local function zoom_in()