language-diff icon indicating copy to clipboard operation
language-diff copied to clipboard

Update theme to hilight whole lines

Open ybart opened this issue 8 years ago • 4 comments

I thought it would be great to hilight the whole diffed lines, so I ended using the following stylesheet:

atom-text-editor::shadow {
  .line {
    position: relative;

    .meta.diff.header::after, .meta.diff.index::after,
    .markup.inserted.diff::after, .markup.deleted.diff::after {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      display: block;
      z-index: -100;
      content: '';
    }

    .meta.diff.header::after, .meta.diff.index::after {
      background-color: #113050;
    }

    .markup.inserted.diff::after {
      background-color: #224422;
    }

    .markup.deleted.diff::after {
      background-color: #442222;
    }

    .markup.inserted.diff {
      color: #ccffcc;
    }

    .markup.deleted.diff {
      color: #ddaaaa;
    }
  }
}

It renders well with my theme (solarized-dark), but colors might need to be changed to use theme colors.

Here is a preview:

capture d ecran 2017-08-09 a 11 05 22

I got the CSS from here : https://discuss.atom.io/t/highlight-entire-line-depending-on-syntax/20653

ybart avatar Aug 09 '17 09:08 ybart

Hi @ybart ! This is a nice idea.

I've been using the built-in mechanisms for selecting colors for the diff text, based on variables that theme designers can then override. Example: https://github.com/miketheman/language-diff/blob/ae623236672ccbd8a3581b3ab8bae2a52e751fde/styles/diff.less#L4-L6

I'm not certain that choosing definitive values is the right way to go here - are you aware of any specific theme color variables that are used across all Atom themes to highlight/invert?

miketheman avatar Aug 11 '17 12:08 miketheman

I'm not aware of such variables names. However, ˋsyntax-backgoround-color-addedˋ might be a good fit.

We might also need to lighten and desature foreground colors as well to achieve a clean result.

Maybe we could also derivate these from syntax-background-color?

ybart avatar Aug 11 '17 16:08 ybart

Hi @ybart - I spent a few hours trying to figure out the right way to do this.

An inherent problem is that I haven't figured out a way to "detect" if the user's theme is a dark or light one, and then shade/tint the colors accordingly. This may exist in LESS or Atom, I haven't found it yet.

The danger of using absolute values is that the behavior changes based on the user's theme, and I want to provide the best possible solution that doesn't look "bad" on a user's screen.

I had tried using contrast to change the background/foreground colors based on the syntax's background, but haven't been able to find the right mix of statements and logic.

I'll leave this issue open for now, but anyone looking to help out with this is welcome to.

miketheman avatar Aug 13 '17 11:08 miketheman

Thanks you very much for your investigation. Unfortunately I don't have much time to investigate now. However I found this stack question interesting. However it will require some time to adjust and test with most common themes.

https://stackoverflow.com/questions/21600825/conditional-css-based-on-background-color-variable

A faster option would be to propose 2 or 3 variants and let the user choose in settings.

ybart avatar Aug 13 '17 12:08 ybart