sebastiencs / company-box

A company front-end with icons
563 stars 64 forks source link

company-box--height doesn't take default line-spacing into account and clips lines #180

Open DivineDominion opened 2 years ago

DivineDominion commented 2 years ago

When displaying the overlay box, the char-height is used to compute the total height of the box:

(-let* (...
        (char-height (frame-char-height frame)) 
        ...))

Thing is: char-height isn't aware of additional line-spacing.

Example

Given this document:

Boooaaaaa
Boooiiiii
Boooooooo

And given (setq-default line-spacing 0) (default),

and company-mode with the capf and dabbrev backend enabled, this is the completion I get when I type another line with "Boo":

Screen Shot 2021-10-12 at 12 52 17 (The box fits all lines exactly)

(dabbrev probably picks up "boolean" from somewhere)

Now set (setq-default line-spacing 0.2), see that the document and the box respect this setting; but the box doesn't take it into account when computing the total height of the box.

Screen Shot 2021-10-12 at 12 52 40 (The box cuts off the last line)

That in turn clips the result list. The total box's height is computed without the extra spacing in mind.

Suggestions

I believe that (line-pixel-height) would be a better fit to calculate the actual line height instead of the character height of the frame.

Example values:

  1. line-spacing is 0.0
    • (frame-char-height): 24
    • (line-pixel-height): 24
  2. line-spacing is 0.2
    • (frame-char-height): 24
    • (line-pixel-height): 28

I'm not sure if (line-pixel-height), which operates on the current window, is as good as a per-frame char-height, or if this has unintended side-effect. It works in my experiments. But the notion of the "current window" could be lots of different things, so I'm not certain if this is truly the best way.