Skip to content

Add indented-code-wrapping feature - #1989

Merged
fregante merged 34 commits into
refined-github:masterfrom
notlmn:soft-wrap
May 24, 2019
Merged

fregante merged 34 commits into
refined-github:masterfrom
notlmn:soft-wrap

Conversation

@notlmn

@notlmn notlmn commented Apr 26, 2019 •

Copy link
Copy Markdown
Contributor

Closes #1908

Uses JS to detect number of spaces at the start of each line, and then uses CSS to move the block forward.

PRs to test

PR conversations and files (dynamically loaded comments, review, and files)

PRs with suggestions

Comment thread source/features/softwrap-code.tsx Resolved
Comment thread source/features/softwrap-code.tsx Resolved
Comment thread source/features/softwrap-code.tsx Resolved
@notlmn

notlmn commented Apr 29, 2019

Copy link
Copy Markdown
Contributor Author

Temporarily blocked by lukechilds/github-custom-tab-size#3.

@notlmn
notlmn marked this pull request as ready for review April 29, 2019 16:54
@fregante

Copy link
Copy Markdown
Member

Interesting solutions. Twice on this PR I was like

g9954

@notlmn

notlmn commented Apr 29, 2019

Copy link
Copy Markdown
Contributor Author

Doesn't exactly show the change in tab size (Gamebar on Windows), but changing value looks something like this:

Comment thread source/features/softwrap-code.tsx Resolved
Comment thread source/features/softwrap-code.tsx Resolved
Comment thread source/features/softwrap-code.tsx Resolved
Comment thread source/features/softwrap-code.tsx Resolved
Comment thread source/features/softwrap-code.tsx Resolved
Comment thread source/features/softwrap-code.tsx Resolved
Comment thread source/features/softwrap-code.tsx Resolved
@notlmn

notlmn commented Apr 29, 2019

Copy link
Copy Markdown
Contributor Author

Need to look into performance of the code, test it out more on ajaxed diff tables in PR files and reviews, decide on name of this feature, and can then only this PR should be good to go.

@fregante fregante changed the title Indentation aware line wrapping Indentation-aware line wrapping Apr 30, 2019

@fregante fregante left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few last changes I think.

In PR Files, files can be loaded asynchronously so we need to listen to that. Look at raw-file-link to see how to implement it. Can you pull out that function into on-pr-file-load.ts?

Comment thread source/features/softwrap-code.tsx Resolved
Comment thread source/features/softwrap-code.tsx Resolved
Comment thread source/features/softwrap-code.tsx Resolved
Comment thread source/features/softwrap-code.css Resolved
Comment thread source/features/softwrap-code.css Resolved
@fregante

fregante commented May 2, 2019 •

Copy link
Copy Markdown
Member

Can you commit to maintain this feature going forward? For example, in case GitHub changes something that breaks it. We already have way too many features to maintain, so we need to find a way to make this sustainable.

If so, can you add a line to CODEOWNERS?

Comment thread source/features/softwrap-code.tsx Resolved
@notlmn

notlmn commented May 2, 2019

Copy link
Copy Markdown
Contributor Author

Can you commit to maintain this feature going forward? For example, in case GitHub changes something that breaks it. We already have way too many features to maintain, so we need to find a way to make this sustainable.

If so, can you add a line to CODEOWNERS ?

I would be glad to, and yes I added my name to the list. Thanks!

…style

Because for some unknown reason in this world, using `!important` or overriding and elements `style` which already has `!important` applied doesn't work from JS. Debuggers work, but not JS. 🤷
Comment thread source/libs/on-pr-file-load.tsx Resolved
@notlmn

notlmn commented May 17, 2019

Copy link
Copy Markdown
Contributor Author
  • ensure that the height doesn't change;

Done.


  • drop the 200ms delay, after ensuring that all the features that rely on it work correctly on: fresh comments (they're auto-loaded as people comment on issues), collapsed review comments, collapsed comments on long discussions.

I have no idea how changing this would affect other features. Ideally all layout changes should be done under 50ms (just a random value off the top of my head). How about lowering the delay instead of dropping it.

line-height: 21px; /* Compensation for block-ifying table cells */
}

.rgh-code-wrapping-enabled .blob-code-hunk, /* Wrap code eagerly to avoid layout changes later */

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • add a rgh-softwrapped-code class on body to enable regular wrapping on all elements before the rest of the javascript runs;

This should do the task, but I'm assuming this might affect fragment-targeted-link-loading (changing layout after page load might move the page over the desired view).

@notlmn

notlmn commented May 18, 2019

Copy link
Copy Markdown
Contributor Author

Is GitHub testing soft-wrapping? I don't remember seeing these CSS classes before.

image

Test PR: sindresorhus/awesome-lint#82

/cc @lukehefson @shayfrendt

@fregante

fregante commented May 24, 2019 •

Copy link
Copy Markdown
Member

The line numbers no longer change (61, 62, 63) but the text moves up in Chrome and Firefox (macOS). Maybe this is ok.

3

@fregante fregante self-assigned this May 24, 2019
1. Open refined-github#1881
2. Expand add-co-authored-by.tsx
3. Notice no indentation change in the "Suggested change" diff
@fregante fregante removed their assignment May 24, 2019
@fregante

Copy link
Copy Markdown
Member

Last note: mixed indentation will break even after the suggested fix a few weeks ago.

If tab-size: 4, \t should not be 3 + 4 characters long but still 4 characters.

Random indentation however should worry us, it should look broken. I think the current implementation still works correctly for "accettable" mixed indentation, like:

 -> -webkit-transform: none;
 -> ••••••••transform: none;

@fregante
fregante merged commit 8dea858 into refined-github:master May 24, 2019
@fregante

fregante commented May 24, 2019 •

Copy link
Copy Markdown
Member

Thanks @notlmn! I think will make the code more readable and is more performant than what I would have come up with 🏎

@notlmn
notlmn deleted the soft-wrap branch May 24, 2019 11:21
@Taluu

Taluu commented May 29, 2019

Copy link
Copy Markdown

Not sure if it's just that I haven't properly looked around, but is there any possibility to disable the soft-wrapping introduced here in unified view ? It's annoying the hell out of me (I can understand though that some may prefer that).

So introducing a button or something to toggle on / off the soft-wrapping.

Can make a new issue if needed.

Thanks.

@fregante

Copy link
Copy Markdown
Member

All the JavaScript features can already be disabled in the options. This one is called indented-code-wrapping

@Taluu

Taluu commented May 29, 2019

Copy link
Copy Markdown

Awesome, didn't see the field in the extension's config.

Is there a list somewhere of all the extensions names (Just being curious) ? :}

Thanks.

@fregante

Copy link
Copy Markdown
Member

In the options itself there’s a link to the list

@fregante

Copy link
Copy Markdown
Member

Can you add this to the readme? It needs simple before/after screenshot (copy-pasted arrows/test from https://user-images.githubusercontent.com/1402241/34438653-f66535a4-ecda-11e7-9406-2e1258050cfa.png)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Wrap code in comments

4 participants