Zoom with neovide scale factor if available

This commit is contained in:
Amanda Graven 2024-05-21 13:22:22 +02:00
parent d6e56e6c96
commit c3158d774c
Signed by: amanda
GPG key ID: F747582C5608F4CB

View file

@ -99,13 +99,9 @@ local zoom_notification = nil
--- "Zoom" by changing gui font size --- "Zoom" by changing gui font size
--- @param delta integer --- @param delta integer
function _G.zoom(delta) 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 = { local properties = {
title = 'Font size',
hide_from_history = true, hide_from_history = true,
render = 'compact',
on_close = function() on_close = function()
zoom_notification = nil zoom_notification = nil
end end
@ -113,7 +109,21 @@ function _G.zoom(delta)
if zoom_notification ~= nil then if zoom_notification ~= nil then
properties.replace = zoom_notification.id properties.replace = zoom_notification.id
end 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 end
local function zoom_in() local function zoom_in()