]> git.gir.st - VimFx.git/commit
Handle a `line-height` special case
authorSimon Lydell <simon.lydell@gmail.com>
Sun, 15 Jun 2014 19:22:41 +0000 (21:22 +0200)
committerSimon Lydell <simon.lydell@gmail.com>
Sun, 15 Jun 2014 19:22:41 +0000 (21:22 +0200)
commit5778a7476aa5786076038b651b4305fb3f867d8f
tree2bc95d7ac3125be421c9164f5f8f83b1462e5427
parentf0c862d489c45c0f6c65ba91bd2504ce9b82177c
Handle a `line-height` special case

Consider the following HTML:

    <p><a href=#>Link text</a></p>

And the following CSS:

    p {
      line-height: 20px;
      font-size: 20px;
      overflow: hidden;
    }
    a {
      font-size: 80px;
    }

Result, with the rectangles of the elements drawn:

    +---------+
    |         |
    |---------+-----------+
    |Link text|           |
    |---------------------+
    |         |
    +---------+

The wide rectangle belongs to the `<p>` while the other belongs to the
`<a>`. The top and bottom part of the `<a>` rectangle, outside of the
`<p>` rectangle (because the `font-size` of `<a>` is larger than the
`line-height`), are hidden due to `overflow: hidden;`.
`document.elementFromPoint()` will only return `<a>` in the area covered
by both rectangles. That is a problem since we start looking at the
top-left corner of the `<a>` rectangle, which will return whatever is
behind.

The solution is to add `line-height: normal;` temporarily to `<a>`,
causing the following (with a comparison to the right):

                               /    +---------+
                               /    |         |
    +---------------------+    /    |---------+-----------+
    |Link text            |    /    |Link text|           |
    |                     |    /    |---------------------+
    |                     |    /    |         |
    |                     |    /    +---------+
    |                     |    /
    +---------------------+    /

This way we can get the correct coordinates, but we only do it as a last
resort, since it is a performance expensive operation.
extension/packages/mode-hints/hints.coffee
extension/resources/style.css
Imprint / Impressum