glacambre / firenvim

Embed Neovim in Chrome, Firefox & others.
GNU General Public License v3.0
4.57k stars 144 forks source link

Completion menu not correctly cleared, leading to screen corruption. #1588

Closed gi1242 closed 4 months ago

gi1242 commented 4 months ago

What I tried to do

Type text, with nvim-cmp enabled.

What happened

The completion menu is shown correctly. However, it is not cleared correctly and it leaves garbled trails all over the screen (see the screenshot below).

image

Please let me know if you need any more information.

THanks in advance,

GI

glacambre commented 4 months ago

Thanks for including a screenshot, this is very useful. I would guess that this bug is caused by Firenvim clearing a single-cell character where it should really be clearing a wide one. I'll see if I can fix it :)

gi1242 commented 4 months ago

Thanks. I suspect the issue might also be related to scaling. On a computer with just one monitor and no display scaling, it works perfectly. I only have issues on a computer with two displays, where one display is scaled. (I'm using Plasma + Wayland and running firefox.)

Let me know if you can reproduce it, or if you need me to try and reproduce it in my one monitor system.

Thanks again.

GI

gi1242 commented 4 months ago

I just confirmed this still happens with just one monitor without scaling. (I also confirmed that this does not happen on my other machine.) I suspect there's some font instalation difference which is causing the bug. I haven't been able to trace it down, so if you have any ideas or suggestions please let me know.

glacambre commented 4 months ago

I think we should try to replace repeat with repeat + 1 here:

https://github.com/glacambre/firenvim/blob/master/src/renderer.ts#L475

It's not great because we'll end up re-drawing the next cell even when it's not needed, but it should take care of the case of double-width characters.

gi1242 commented 4 months ago

I can confirm it's the wide characters causing the problem. If I disable the icons in my completion menus and just use text, then everything is cleared correctly.

I also can't get the icons to show up correctly in firenvim. They look like the screenshot above. In a terminal (or in nvim-qt), I see proper LSP icons with nerd fonts. However, in firenvim I can't get them to show up. So that might be messing up the width calculations...

Regardless, clearing an extra character won't be too much of a performance hit (I hope).

Thanks again,

GI

glacambre commented 4 months ago

I also can't get the icons to show up correctly in firenvim.

Yes, unfortunately Firenvim cannot enumerate installed fonts nor the characters they contain, so the only thing it can do is draw characters hoping that they'll get rendered properly :(

gi1242 commented 4 months ago

Yes, unfortunately Firenvim cannot enumerate installed fonts nor the characters they contain, so the only thing it can do is draw characters hoping that they'll get rendered properly :(

Strange. Emojis like 😄 show up just fine. But the Nerd font symbols don't show up...

Thanks for your quick responses

glacambre commented 4 months ago

Nerd font symbols don't show up...

Oh, okay, this explains everything. Nerd fonts are not "real" fonts, they patch existing fonts to assign more glyphs to unused characters. It's likely that Firenvim is not using your Nerd font but a "normal", unpatched one.

gi1242 commented 4 months ago

Oh, okay, this explains everything. Nerd fonts are not "real" fonts, they patch existing fonts to assign more glyphs to unused characters. It's likely that Firenvim is not using your Nerd font but a "normal", unpatched one.

Oh I see. I'll disable LSP icons during firenvim, which should make it usable for me.

Strange that I see screen corruption on one machine, and none on another (almost identically configured) machine....

Thanks again,

gi1242 commented 4 months ago

For anyone using Nerd fonts: If you put the nerd font before the regular font in your font-config then everything works perfectly. In my case I edited ~/.config/fontconfig/conf.d/50-defaults.conf and did this:

 <alias>
  <family>monospace</family>
  <prefer>
   <family>DejaVuSansM Nerd Font Mono</family>
   <family>Dejavu Sans Mono</family>
   ...
  </prefer>
 </alias>