sindresorhus/refined-github

Do you want to work on this issue?

You can request for a bounty in order to promote it!

`extend-diff-expander` only expands down when expands up is also available #4736

WEGFan posted onGitHub

Please ensure:

  • The bug is caused by Refined GitHub. It doesn't happen if I disable the extension.

Description

Title says it all

Screenshot

Snipaste_2021-08-29_00-31-54

Console errors

No response

Example URL

https://github.com/sindresorhus/refined-github/commit/e8ec186217ffc42f351983b22187ee14efb9251b#diff-6a8348ff857b16e455a52ddd651b49f31cd05895459c37301051a0e30bcf077c

Browser(s) used

Firefox 91.0.2 & Chrome 92.0.4515.159


Yep that's how it is. The feature is very simple and the element is one (you can tell by the text sitting in the middle).

I've always been annoyed by it, maybe we can fix it by adding :before and :after pseudo elements via CSS for the hover and then detect which side has been clicked via JS

If anyone wants to pick this up, I expect maybe 10 lines of CSS and 5 lines of JavaScript in the click listener, no DOM changes.

posted by fregante over 3 years ago

maybe we can fix it by adding :before and :after pseudo elements via CSS for the hover

Sadly, :hover can't be applied to pseudo-elements. The JS part should be pretty simple though, maybe we can fix at least that?

posted by cheap-glitch over 3 years ago

The JS part should be pretty simple though, maybe we can fix at least that?

How? Would it open the right sight even if there's no indication that the click position is affected?

maybe we can fix it by adding :before and :after pseudo elements via CSS for the hover

Sadly, :hover can't be applied to pseudo-elements.

Indeed.

There are 2 buttons here, so we could use a :after pseudo element on both in order to extend them. However it appears that I can't extend them outside the td, as if there was a overflow:hidden. Nor can they be relative to the tr 🤷‍♂️ Example:

.js-expand.directional-expander {
      position: relative;
}
.js-expand.directional-expander:after {
      content: "";
      position: absolute;
      border-top: solid red 2px;
      top: 0;
      left: 0;
      width: 600px;
}

An additional issue would be the style, since we can't quite match the style for half the element. Maybe a top/bottom border would be enough to show something is happening.

Note: I'd like to avoid using delegate('mouseenter') because that would happen hundreds of times on every mouse movement across the page.

posted by fregante over 3 years ago

How?

function expandDiff(event: delegate.Event<MouseEvent>): void {
    // Skip if the user clicked directly on the icon
    if (!(event.target as Element).closest('.js-expand')) {
        const direction = event.offsetY >= (event.target as HTMLElement).offsetHeight / 2 ? 'Up' : 'Down';
        select(`.js-expand:is([title="Expand ${direction}"], .single-expander)`, event.delegateTarget)!.click();
    }
}

Adds only one new line (and doesn't break single-direction expanders). Tested in Firefox only.

There are 2 buttons here, so we could use a :after pseudo element on both in order to extend them.

Thought about it too, but pseudo-elements don't actually extend their parent's "clickable zone", since they have no real existence in the layout.

The thing is, I don't think there is a pure-CSS way to tell whether the mouse hovers on the top or bottom-half of an element. (Unless there's some kind of clever hack we could use…)

posted by cheap-glitch over 3 years ago

The trick I mentioned with :before would work but table stuff breaks a lot of CSS, including positioning.

I wonder if we can change the display of tr to flex without breaking the layout. That would allow the :before trick inside each link.

posted by fregante over 3 years ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests