-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support soft wrap for line numbers plugin #584
Conversation
codeLines.forEach(function(line, lineNumber){ | ||
lineNumberSizer.innerText = line; | ||
var lineSize = lineNumberSizer.getBoundingClientRect().height || lineHeight; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the fallback? In which case would we get there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are about line 21-23:
Empty line? Something like:
var a = 5;
var b = 6;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, probably it was legacy from old scenario, and can be deleted.
in forEach block empty line height calculating with same scenario.
I can update the pull request with removing this lines (20-23).
Everything else?
Any updates on this one? |
This looks quite good to me, though I did not take the time to properly download it to test it. Did you make sure it was still compatible with other plugins, different themes, etc.? |
@Golmote one more update - I've updated test.html with support for testing plugins. I've tested in different browsers - everything is fine for me :) |
Thanks for contributing! |
On the topic of separate pull requests, if you wish to modify the general code structure of a file, please send a separate PR to do that and a separate PR for any other changes. In general, the smaller the PRs (obviously as long as they’re coherent), the better. From a quick look, it seems that the changes in the line numbers plugin are way more extensive than required for this change (but I might be wrong). |
Also, I’m not a huge fan of using a |
@LeaVerou, definitely, I will separate them soon when I will have time for it. About class name. It was just my decision. I can make it to be automatically, if you wish so. |
…y by white-space css attribute on the pre tag
I can say that the indentation is a bit messed up right now. Please use tabs (and this applies to CSS too). Now about the plugin code itself:
|
@Golmote the previous implementation was just about it - just when you adding a class - everything is rock & roll. What do you think? P.S. Yes, already removed that gitignore from my branch, sorry for that. |
+1! :) |
Sorry for the long time waiting. It appears to work just fine. Thank you very much for this contribution! |
@Golmote wow, man, 2.5 years. Amazing, I'm already married and visited 8 countries by this time :D |
@VitaliyR Better late than never! |
I seems line highlighting does not work properly when soft wrap is enabled. |
@siavashs Indeed I should have expected that. Those are two different plugins... I'll open a new issue so that it can be handled at some point. |
Hello.
In my past project I had a requirement to highlight code, show line numbers and have support of soft wrap lines (so no horizontal scroll).
I found that originally line numbers plugin is very simple and doing its job very well but when it comes to white-space: pre-wrap - it is breaks.
I made a fix which adds support of soft wrap for this plugin.
Let's discuss it?
Generally the most interesting part, probably, is in 'sizer' functionality. It is calculating line-height. Why I not used line-height property? Because there are different problems with it: it can be line-height: normal (so God knows how much is that), the browser zoom level can be changed (and line-height actually is inc/decreasing) etc.
So, maybe it is a bit silly, but still working solution :) (any ideas how to make it better? Would be nice to discuss)