toppair / peek.nvim

Markdown preview plugin for Neovim
MIT License
624 stars 42 forks source link

feat: add zoom functionality #58

Closed fmorroni closed 6 months ago

fmorroni commented 6 months ago

Adds zoom functionality by means of the css zoom property. It's probably not ideal as zoom is non-standard, but it works fine in my system. I tried using transform: scale() as is recommended, but that leaves content outside of the visible window area so it didn't really work. The zoom is bound to +, - and * for zoom up, down and reset to 100% respectively. I added it for use in webview, but is also active when using the browser option. This may be undesired (although it seems to work fine there too, at least in brave).

fmorroni commented 6 months ago

Demo

https://github.com/toppair/peek.nvim/assets/88512894/d5a7dd16-afc7-4faa-bbf0-cfd1c2832a81

toppair commented 6 months ago

Thanks. zoom breaks some tex math rendering. Plus, as you mentioned, it's non standard. I almost managed to make it work with scale, but webview doesn't seem to handle it like browsers do either. Whole page becomes blurry when there are overflowed elements like <code> blocks present. I didn't find simple solution to this and don't want to go into detail and try to scale/adjust/css-hack individual elements to make it work. Issue this PR is addressing mentions only font-size though so I went with scaling font instead. I think it's sufficent for accesibility and won't introduce possibly unfixable issues later. Since this is generally already supported by browsers I made your component active only for app = 'webview', changed keybinds to align with those used by browsers and introduced caching and restoring zoom level like browsers seem to do.

fmorroni commented 6 months ago

Great, I also think scaling the font directly is a better idea. I did try that briefly but the font scaling wasn't getting inherited so I went with zoom. I must've been doing it wrong haha Keybind for zoom increase is <c-+> in my browser tho, never seen it used with <c-=>. But it may be due to keyboard locale (I use latam).